首页 > jquery验证问题

jquery验证问题



var shopRegist="";
   var shopCount=1;
   var maxCount=6;
   var rztip="";
   $("#shopRegist .addTel").click(function(event) {
       shopCount++;
       if(shopCount<maxCount){
          shopRegist="<span class='add'><input type='text' class='form-control user req' id='rzTel_"+shopCount+"' ><a href='#' class='delTel'><img src='img/del.png' alt='删除'></a></span>"; 
          $(this).parent().append(shopRegist);
       }
       else{
        shopCount=maxCount-1;
         $("#shopRegist .addTel").parent().find(".erro").remove();
         shopRegist="<span class='add erro'>最多只能添加"+(maxCount-1)+"个</span>";
         $("#shopRegist .addTel").parent().append(shopRegist);
       }
       return false;
    }); 
   
        $("#shopRegist").on('click','.delTel',function(){
            shopCount--;
            if(shopCount<maxCount){
         $("#shopRegist .addTel").parent().find(".erro").remove();              
            }
           $(this).parent("span").remove();    
           return false;
        })
    $("#shopRegist input[type='file']").change(function(event) {
        var thisIndex=$(this).val().lastIndexOf("\\");
        $(this).nextAll("span").html($(this).val().substr(thisIndex+1)).addBack().addClass('cololv');   
    });
    function validate(form){
         var inp=$("#"+form+" .req");
         var $sub=$("#"+form+" .sub");
         var $tel=$("#"+form+" .tel");
         $.each(inp,function(index){
            var thiss=$(this);
             $sub.click(function() {
                thiss.parent().find("b").remove();
                   if(thiss.attr("type")=="checkbox"){
                        if(thiss.prop("checked")==false){
                            alert("请阅读并同意《帘盟网用户协议》");
                            return false;
                        }
                        else{
                            return true;
                        }
                 }
                 else if(thiss.attr("type")=="text"||thiss.attr("type")=="file"){           
                    thiss.on("blur change focus",function(){
                         $(this).parent().find("b").remove();
                        rztip="<b class='succ'><img src='img/zc-succ.png'></b>";
                        if(thiss.val()!==""){
                        thiss.parent().append(rztip);
                        }
                        if(thiss.attr("class").indexOf("tel")>-1){

                         if(!(telReg($tel.val()))){
                        $tel.parent().find("b").remove();
                         rztip="<b class='fail'><img src='img/zc-fail.png'>手机号码格式错误</b>";
                         $tel.parent().append(rztip);
                     return false;
                        }

                        }
                    })
                    if(thiss.val()==""){
                        var ziduan=thiss.prevAll("label").text();
                        ziduan=ziduan.replace(/:/g,"");
                       rztip="<b class='fail'><img src='img/zc-fail.png'>"+ziduan+"不能为空</b>";
                       thiss.parent().append(rztip);
                       if(!(telReg($tel.val()))){
                        $tel.parent().find("b").remove();
                         rztip="<b class='fail'><img src='img/zc-fail.png'>手机号码格式错误</b>";
                         $tel.parent().append(rztip);
                     return false;
                     }
                    }
                     if(thiss.attr("class").indexOf("tel")>-1){

                         if(!(telReg($tel.val()))){
                        $tel.parent().find("b").remove();
                         rztip="<b class='fail'><img src='img/zc-fail.png'>手机号码格式错误</b>";
                         $tel.parent().append(rztip);
                         return false;
                        }
                         else{
                            rztip="<b class='succ'><img src='img/zc-succ.png'></b>";
                            thiss.parent().append(rztip);
                         

                         }
                        }
                    else{
                      rztip="<b class='succ'><img src='img/zc-succ.png'></b>";
                      thiss.parent().append(rztip);
                    }
                    window.location.href="shop-record.html";
                    return false; 
                 }

                    // else{
                    //     window.location.href="shop-record.html";
                    //     return false; 
                    // }

             });

         })
         
    }
    validate("shopRegist");
【热门文章】
【热门文章】