表单
什么是表单?
- 向服务器提交数据,比如用户注册
- 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>
目标很遥远,但是如果你拼了命努力,即使到最后没有达到目标,但是你会发现,在某种程度上你已经成功了。