源代碼
點擊運行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>教程</title> <script> function getLength(){ alert(document.getElementById("mySelect").length); } </script> </head> <body> <form> <select id="mySelect"> <option>蘋果</option> <option>梨子</option> <option>香蕉</option> <option>橙子</option> </select> <input type="button" onclick="getLength()" value="列表有幾種選擇?"> </form> </body> </html>
運行結果