在下拉列表中显示所选选项

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script>
  5. function getOption() {
  6. var obj = document.getElementById("mySelect");
  7. document.getElementById("demo").innerHTML =
  8. obj.options[obj.selectedIndex].text;
  9. }
  10. </script>
  11. </head>
  12. <body>
  13.  
  14. <form>
  15. 请选择您喜欢的水果:
  16. <select id="mySelect">
  17. <option>Apple</option>
  18. <option>Orange</option>
  19. <option>Pineapple</option>
  20. <option>Banana</option>
  21. </select>
  22. <br><br>
  23. <input type="button" onclick="getOption()" value="点击这里">
  24. </form>
  25.  
  26. <p id="demo"></p>
  27.  
  28. </body>
  29. </html>