您的位置:首页 > Web前端 > JQuery

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

2015-01-04 11:43 721 查看
//自定义验证输入价格
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")
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: