標籤:
//自訂驗證輸入價格jQuery.validator.addMethod("PriceCheck", function (value, element) { var breakNumber=0; $(".producPrice").each(function (k, v) { if ($.trim($(this).val()) == "") { $(this).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") });
jquery validate 自訂驗證方法(不固定驗證)