编辑下面的代码:【加编码】
<html> <head> <script> function displayResult() { var x=document.getElementById("mySelect").selectedIndex; alert(document.getElementsByTagName("option")[x].value); } </script> </head> <body> <form> Select your favorite fruit: <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()">Display value of selected fruit</button> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂