jquery Simple Form Validation effect

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.