在下拉列表中显示所选选项的索引
- <!DOCTYPE html>
- <html>
- <head>
- <script>
- function getIndex() {
- document.getElementById("demo").innerHTML =
- document.getElementById("mySelect").selectedIndex;
- }
- </script>
- </head>
- <body>
- <form>
- 请选择您喜欢的水果:
- <select id="mySelect">
- <option>Apple</option>
- <option>Orange</option>
- <option>Pineapple</option>
- <option>Banana</option>
- </select>
- <br><br>
- <input type="button" onclick="getIndex()"
- value="显示所选选项的索引">
- </form>
- <p id="demo"></p>
- </body>
- </html>