submit event
Definition and usage
The submit event occurs when a form is submitted.
This event only applies to form elements.
Thesubmit() method triggers the submit event, or specifies a function to be run when the submit event occurs.
Syntax
$('').submit()
Let’s analyze it in detail, look at the code below
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>submit</title> <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script> </head> <body> <form action="#" method="post" name="form"> 用户名:<input type="text" placeholder="请输入用户名"></br></br> 用户名:<input type="password" placeholder="请输入密码"></br></br> <input type="submit" value="提交"> </form> </body> </html>
As shown in the above code, our form does not add events, but it will be submitted to a place by default. That is, when we learn the PHP scripting language later, we will process the form
So how do we do this? If the page is processed on the client side, then I need some jquery code to process the form
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>submit</title> <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script> </head> <body> <form action="#" method="post" name="form"> 用户名:<input type="text" placeholder="请输入用户名"></br></br> 用户名:<input type="password" placeholder="请输入密码"></br></br> <input type="submit" value="提交"> </form> <script> $('form').submit(function(){ alert('error'); }) </script> </body> </html>
As shown in the above code, we submit the form, click the button, trigger the submit event, and pop up an error message, like this We can process the form on this page, such as user name rules and password rules. If they are not met, the form will not be submitted to another page for processing