Home > Web Front-end > JS Tutorial > Implementing form submission verification based on jQuery_jquery

Implementing form submission verification based on jQuery_jquery

WBOY
Release: 2016-05-16 16:30:34
Original
1372 people have browsed it

html form code:

Copy code The code is as follows:


                                                                                                            
             
                                                                                                                                                                                                                                   
              
                                                                                                                                                                                                                    
                                          
                                                                                                                                                                                             
                                          
                                                                                       




jQuery code:




Copy code

The code is as follows:


             $(function(){
                $("form :input.required").each(function(){
              var $required = $("*");
//$(this).parent().append($required); //Append to the document
                      $(this).parent().prepend($required);
              });
                 $('form :input').blur(function(){
              var $parent = $(this).parent();
If($(this).is('#username')){
If(this.value==""||this.value.length<6){
                                                                                                      var errorMsg = 'Please enter a username of at least 6 characters';
                                     $parent.append('' errorMsg '');
                           }else{
                                                                                                                                                                                                                                                                        var okMsg = 'Correct input';
                                     $parent.append('' okMsg '');
                                                                                                                                                                                                                              If($(this).is('#email')){
if(this.value==""||(this.value!=""
&&!/. @. .[a-zA-Z]{2,4}$/.test(this.value
))){                                 var errorMsg = 'Please enter the correct email address'; $parent.append('' errorMsg '');
                                                                                                                                                                                                                                                                                                                                                                                                                                          var okMsg = 'Correct input';
                                       $parent.append('' okMsg '');
                                                                                                                                                                                                                                                                                                 });
                $("form :input").focus(function(){
              var $parent = $(this).parent();
                       $parent.find(".formtips").remove();
              });
                 $("#send").click(function(){
              var $parent = $(this).parent().parent();
                     $parent.find(".formtips").remove();
                      $("form .required:input").trigger('blur');
              var numError = $('form .onError').length;
If(numError){
                          return false;
                                                                                                  });
                 $("#res").click(function(){
              var $parent = $(this).parent().parent();
                       $parent.find(".formtips").remove();
              });
        });

The code is very simple and easy to understand. Friends, just take it and use it. I won’t explain it in detail here.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template