更改所选选项的文本
- <html>
- <head>
- <script type="text/javascript">
- function changeText()
- {
- var x=document.getElementById("mySelect")
- x.options[x.selectedIndex].text="Melon"
- }
- </script>
- </head>
- <body>
- <form>
- Select your favorite fruit:
- <select id="mySelect">
- <option>Apple</option>
- <option>Orange</option>
- <option>Pineapple</option>
- <option>Banana</option>
- </select>
- <br /><br />
- <input type="button" onclick="changeText()" value="设置所选选项的文本">
- </form>
- </body>
- </html>