编辑下面的代码:【加编码】
<html> <head> <script> function displayResult() { var x=document.getElementById("mySelect").selectedIndex; var y=document.getElementById("mySelect").options; alert("Index: " + y[x].index + " is " + y[x].text); } </script> </head> <body> <form> Select your favorite fruit: <select id="mySelect"> <option>Apple</option> <option>Orange</option> <option>Pineapple</option> <option>Banana</option> </select> </form> <button type="button" onclick="displayResult()">Display index</button> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂