<!DOCTYPE html>
<html>
<body>
<form>
<input list="browsers" name="browser">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
</form>
<p>单击该按钮可显示数据列表中所有选项元素的值。</p>
<button type="button" onclick="myFunction()">试一试</button>
<p><b>注释:</b>Internet Explorer 9 及更早版本或 Safari 不支持 datalist 元素。</p>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("browsers");
var txt = "";
var i;
for (i = 0; i < x.options.length; i++) {
txt = txt + x.options[i].value + "<br>";
}
document.getElementById("demo").innerHTML = txt;
}
</script>
</body>
</html>