W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <head> <script> function getIndex() { document.getElementById("demo").innerHTML = document.getElementById("mySelect").selectedIndex; } </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="getIndex()" value="显示所选选项的索引"> </form> <p id="demo"></p> </body> </html>