onsubmit - 当用户点击提交按钮

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script>
  5. function confirmInput() {
  6. fname = document.forms[0].fname.value;
  7. alert("Hello " + fname + "!您现在将被重定向到 www.baidu.com");
  8. }
  9. </script>
  10. </head>
  11. <body>
  12.  
  13. <form onsubmit="confirmInput()" action="http://www.baidu.com/">
  14. 请输入您的姓名:<input id="fname" type="text" size="20">
  15. <input type="submit">
  16. </form>
  17.  
  18. </body>
  19. </html>