时间: 2020-11-24|43次围观|0 条评论

什么是表单?

  • 向服务器提交数据,比如用户注册
  • action     提交到哪里

表单事件

  • onsubmit   提交时发生
  • onreset      重置时发生

示例:

 1 <!doctype html>
 2 <html>
 3 <head>
 4      <meta charset="utf-8">
 5      <title>未命名</title>
 6      <script>
 7      window.onload=function()
 8      {
 9         var oForm=document.getElementById('form');
10         var oUser=document.getElementsByName('user')[0];
11         var oPass=document.getElementsByName('pass')[0];
12         
13         oForm.onsubmit=function()
14         {
15             if(oUser.value==''||oPass.value=='')
16             {
17                 alert('填错了');
18                 return false;  //阻止默认行为
19             }
20         }
21         oForm.onreset=function()
22         {
23             /*if(confirm('是否清空'))
24             {
25                 return true;
26             }
27             else
28             {
29                 return false;
30             }*/
31             
32             return confirm('是否清空');
33         }
34      }    
35      </script>
36 </head>
37 <body>
38      <form id="form" action="www.baidu.com" method="get">
39      user:
40         <input type="text" name="user"/>
41      password:    
42         <input type="password" name="pass"/>
43         <input type="submit" value="submit">
44         <input type="reset" value="resetting">
45      </form>
46 </body>
47 </html>    

 

转载于:https://www.cnblogs.com/Cavalary/p/7806815.html

原文链接:https://blog.csdn.net/weixin_30342827/article/details/99462066

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《表单
   

还没有人抢沙发呢~