更改所选选项的文本

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function changeText()
  5. {
  6. var x=document.getElementById("mySelect")
  7. x.options[x.selectedIndex].text="Melon"
  8. }
  9. </script>
  10. </head>
  11. <body>
  12.  
  13. <form>
  14. Select your favorite fruit:
  15. <select id="mySelect">
  16. <option>Apple</option>
  17. <option>Orange</option>
  18. <option>Pineapple</option>
  19. <option>Banana</option>
  20. </select>
  21. <br /><br />
  22. <input type="button" onclick="changeText()" value="设置所选选项的文本">
  23. </form>
  24.  
  25. </body>
  26. </html>
  27.  
  28.