jquery simple Form Validation effect:
As long as there is a form of the place, basic will have form validation, the following is a combination of examples of the simplest form validation, how to prevent the filling of the form content is empty.
The code example is as follows:
<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metaname= "Author"content= "http://www.51texiao.cn/" /><title>Ant Tribe</title><Scripttype= "Text/javascript"src= "Mytest/jquery/jquery-1.8.3.js"></Script><Scripttype= "Text/javascript">$ (document). Ready (function(){ $("#bt"). Click (function(){ if($("#username"). Val ()=="") {alert ("the user name cannot be empty! "); return false; } if($("#pw"). Val ()=="") {alert ("The password cannot be empty! "); return false; } }) }) </Script></Head><Body><formAction= "http://www.51texiao.cn"name= "MyForm"> <Table> <TR> <TD>User name:</TD> <TD><inputtype= "text"name= "username"ID= "username" /></TD> </TR> <TR> <TD>Password:</TD> <TD><inputtype= "Password"name= "PW"ID= "PW" /></TD> </TR> <TR> <TDcolspan= "2"><inputtype= "Submit"value= "Submit"ID= "BT" /></TD> </TR> </Table></form></Body></HTML>
The above code can be submitted in the form to verify whether the form is empty, if the empty pop-up is a prompt box, the following is a brief introduction to how to achieve this effect:
One. The Submit button binds a point-and-click event handler, that is, when the Submit button is clicked, the binding handler is executed.
Two. In the event handler function, if ($ ("#username"). val () = = "") can determine whether the user name is empty, if empty, a prompt box pops up, and there will be a return false statement, if ($ ("#pw"). val () = = "") The same is true of the role.
The original address is: http://www.51texiao.cn/jqueryjiaocheng/2015/0427/239.html
jquery Simple Form Validation effect