取得下拉列表中选项的数目

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function getLength()
  5. {
  6. alert(document.getElementById("mySelect").length)
  7. }
  8. </script>
  9. </head>
  10. <body>
  11.  
  12. <form>
  13. <select id="mySelect">
  14. <option>苹果</option>
  15. <option>桃子</option>
  16. <option>香蕉</option>
  17. <option>桔子</option>
  18. </select>
  19. <input type="button" onclick="getLength()" value="在这个列表中,有多少选项?">
  20. </form>
  21.  
  22. </body>
  23. </html>