运行 ❯
获取您的
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h3>A demonstration of how to access a DATALIST element</h3> <form> <input list="myDatalist"> <datalist id="myDatalist"> <option value="Internet Explorer"> <option value="Firefox"> <option value="Chrome"> <option value="Opera"> <option value="Safari"> </datalist> </form> <p>Click the button to get the number of option elements in the datalist.</p> <button onclick="myFunction()">Try it</button> <p><strong>Note:</strong> The input element's list attribute is used to bind it together with the datalist element.</p> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myDatalist").options.length; document.getElementById("demo").innerHTML = "Found " + x + " options in the list."; } </script> </body> </html>