Recently, when writing a page, you need to manually write some validation before the form is submitted, just see 2 ways to block form submission, you can do some logical processing
Method One: Use return False
Native JS notation:<form id= "LoginForm" name= "LoginForm" action= "Login.aspx" method= "POST" > <button type= "Submit" value= "submit "Id=" >Submit</button></form><script> "Submit"varSUBMITBTN = document.getElementById ("Submit"); Submitbtn.onclick=function(Event) {alert ("Preventdefault!"); return false; };</script>jquery notation:<script>$("#loginForm"). Submit (function(){if(condition) {//Here's the logical processing here .}Else{ return false;}})</script>//one of the problems found here is that when you use the JQ notation, as long as you do not return FALSE, the logical processing will automatically submit the form
Method Two: Use Preventdefault ()
var submitbtn = document.getElementById ("Submit"function (event) { alert (" Preventdefault! " ); var event = Event | | window.event; // compatible with standard browsers false // compatible with ie6~8 }; </script>
JS action before the form is submitted