Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 41 lines (39 sloc) 1.29 KB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Color Datalist</title>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
</head>
<body>
<input type="text" name="color" id="color" value="" list="colorlist" />
<datalist id="colorlist">
<select style="display: none;">
<option value="Black" />
<option value="Blue" />
<option value="Dark Green" />
<option value="Grey" />
<option value="Green" />
<option value="Red" />
<option value="White" />
<option value="Yellow" />
</select>
</datalist>
<script>
$(document).ready(function () {
var nativedatalist = !!('list' in document.createElement('input')) &&
!!(document.createElement('datalist') && window.HTMLDataListElement);
if (!nativedatalist) {
$('input[list]').each(function () {
var availableTags = $('#' + $(this).attr("list")).find('option').map(function () {
return this.value;
}).get();
$(this).autocomplete({ source: availableTags });
});
}
});
</script>
</body>
</html>