取得下拉列表中选项的数目
- <html>
- <head>
- <script type="text/javascript">
- 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>