jquery validate 自定义验证方法(不固定验证)

来源:互联网 发布:昆仑墟暗器进阶数据 编辑:程序博客网 时间:2024/05/16 11:49
//自定义验证输入价格jQuery.validator.addMethod("PriceCheck", function (value, element) {    var breakNumber=0;    $(".producPrice").each(function (k, v) {        if ($.trim($(v).val()) == "") {            $(v).focus();            breakNumber++;            return false;        }    });    if(breakNumber>0){    return false;    }else{    return true;    }}, "请输入价格");

 

<table cellspacing="0" border="0" style="border-collapse:collapse;"><tbody>    <tr>    <td style="text-align: right;">445</td>    <td style="text-align: left;"><input type="text" class="form-control producPrice" placeholder="价格" id="txtPrice" name="txtPrice" pid="1"></td>   </tr>   <tr>   <td style="text-align: right;">test</td>   <td style="text-align: left;"><input type="text" class="form-control producPrice" placeholder="价格" id="txtPrice" name="txtPrice" pid="3"></td>   </tr></tbody></table>

 

我生成了数个类样式为producPrice的输入框。

 

验证:

$("#form1").validate({        rules: {            txtLoginName: {                required: true                //remote: remoteHasAUserNameFun()            }            txtPrice:{                PriceCheck:true            }        },        messages: {            txtLoginName: {                required: "请输入账号"            }        },        errorLabelContainer: $(".bg-info")    });

 

0 0
原创粉丝点击