執行 ❯
建立您
自己的
網站
×
更改方向
儲存程式碼
更改主題,深色/淺色
前往 Spaces
<!DOCTYPE html> <html> <body> <p>Click the button to create an INPUT field, a DATALIST element and an OPTION element.</p> <form id="myForm"> </form> <button onclick="myFunction()">Try it</button> <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>