在下拉列表中显示所选选项
- <!DOCTYPE html>
- <html>
- <head>
- <script>
- function getOption() {
- var obj = document.getElementById("mySelect");
- document.getElementById("demo").innerHTML =
- obj.options[obj.selectedIndex].text;
- }
- </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="getOption()" value="点击这里">
- </form>
- <p id="demo"></p>
- </body>
- </html>