W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <head> <script> function getOption() { var obj = document.getElementById("mySelect"); document.getElementById("demo").innerHTML = obj.options[obj.selectedIndex].text; } </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="getOption()" value="点击这里"> </form> <p id="demo"></p> </body> </html>