//自定义验证输入价格 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")
});