fmpq.com
源代码:
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Fmpq教程(fmpq.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>
运行结果