W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <head> <script> function getOptions() { var x = document.getElementById("mySelect"); var txt = ""; var i; for (i = 0; i < x.length; i++) { txt = txt + " " + x.options[i].text; } document.getElementById("demo").innerHTML = txt; } </script> </head> <body> <form> 请选择您喜欢的水果: <select id="mySelect"> <option>Apple</option> <option>Orange</option> <option>Pineapple</option> <option>Banana</option> </select> <br><br> <input type="button" onclick="getOptions()" value="输出所有选项"> </form> <p id="demo"></p> </body> </html>