源代碼
點擊運行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>教程</title> <script> function getIndex(){ var x=document.getElementById("mySelect"); alert(x.selectedIndex); } </script> </head> <body> <form> 你喜歡的水果是: <select id="mySelect"> <option>蘋果</option> <option>橙子</option> <option>菠蘿</option> <option>香蕉</option> </select> <br><br> <input type="button" onclick="getIndex()" value="彈出選中項"> </form> </body> </html>
運行結果