onchange - 当用户选择下拉值时
- <!DOCTYPE html>
- <html>
- <head>
- <script>
- function preferedBrowser() {
- prefer = document.forms[0].browsers.value;
- alert("你喜欢使用 " + prefer + " 在网上冲浪!");
- }
- </script>
- </head>
- <body>
- <form>
- 请选择您喜欢的浏览器:
- <select id="browsers" onchange="preferedBrowser()">
- <option value="Chrome">Chrome</option>
- <option value="Internet Explorer">Internet Explorer</option>
- <option value="Firefox">Firefox</option>
- </select>
- </form>
- </body>
- </html>