x
 
<!DOCTYPE html>
<html>
<body>
<p>单击按钮可创建一个 INPUT 字段、一个 DATALIST 元素和一个 OPTION 元素。</p>
<form id="myForm">
</form>
<button onclick="myFunction()">试一试</button>
<p><b>注释:</b>Internet Explorer 9 及更早版本或 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>