基于jQuery实现表单提交验证


html表单代码:

&&!/.+@.+\.[a-zA-Z]{2,4}$/.test(this.value))){
                        var errorMsg = '请输入正确的E-mail地址';
                        $parent.append('<span class="formtips onError">'+errorMsg+'</span>');
                    }else{
                        var okMsg = '输入正确';
                        $parent.append('<span class="formtips onSuccess">'+okMsg+'</span>');
                    }
                }
            });
            $("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();
            });
        });

代码很简单,也很易懂,小伙伴们直接拿走用吧,这里就不详细说明了。


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3