<html>
<body>
<p>点击按钮创建 INPUT 字段, DATALIST 元素及 OPTION 元素。</p>
<form id="myForm">
</form>
<button onclick="myFunction()">点我</button>
<p><strong>注意:</strong> Internet Explorer 9 和更早IE版本,Safari浏览器均不支持 datalist 元素。</p>
<script>
function myFunction()
{
var x = document.createElement("INPUT");
x.setAttribute("list", "browsers");
document.getElementById("myForm").appendChild(x);
var y = document.createElement("DATALIST");
y.setAttribute("id", "browsers");
document.getElementById("myForm").appendChild(y);
var z = document.createElement("OPTION");
z.setAttribute("value", "Chrome");
document.getElementById("browsers").appendChild(z);
}
</script>
</body>
</html>