<html> <head> <script type="text/javascript"> function alertIndex() { var x=document.getElementById("mySelect").selectedIndex; var y=document.getElementsByTagName("option"); alert(y[x].text + " has the index of: " + y[x].index); } </script> </head> <body> <form> 請選擇您喜歡的水果: <select id="mySelect"> <option>蘋果</option> <option>桃子</option> <option>香蕉</option> <option>桔子</option> </select> <br /> <br /> <input type="button" onclick="alertIndex()" value="顯示被選水果的 index"> </form> </body> </html>