JavaScript 参考手册
Option value 属性
显示已选择的选项
源代码:
点击运行 »
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>蜜蜂教程(mifengjc.com)</title> <script> function displayResult() { var x = document.getElementById("mySelect").selectedIndex; alert(document.getElementsByTagName("option")[x].value); } </script> </head> <body> <form> 选择你最喜欢的水果: <select id="mySelect"> <option value="apple">Apple</option> <option value="orange">Orange</option> <option value="pineapple">Pineapple</option> <option value="banana">Banana</option> </select> </form> <button type="button" onclick="displayResult()">选择的水果的值。</button> </body> </html>
运行结果:
点击运行 »