动态添加Jquery自定义规则
我有一个自定义规则:动态添加Jquery自定义规则,jquery,Jquery,我有一个自定义规则: jQuery.validator.addMethod("greaterThanStartPrice", function(value, element, param) { return this.optional(element) || (parseFloat(value) > $(param).val()); }, "\"Reserve Price\" must be greater than \"Start Price\""); 检查输入框b中的值是否大于输入框
jQuery.validator.addMethod("greaterThanStartPrice", function(value, element, param) {
return this.optional(element) || (parseFloat(value) > $(param).val());
}, "\"Reserve Price\" must be greater than \"Start Price\"");
检查输入框b中的值是否大于输入框a。此规则非常有效,但它所应用的表单字段是动态的,因此我还有:
$("#txtReservePrice").rules("remove");
删除该规则。该规则在以下情况下启动:
$("#frmEditListingAuction").validate({
meta: "validate",
rules : {
txtReservePrice:{
greaterThanStartPrice:"#txtStartPrice",
}
}
});
我在重新添加规则时遇到问题。我试过:
$("#txtReservePrice").rules("add", "greaterThanStartPrice");
$("#txtStartPrice").rules("add", "greaterThanStartPrice");
但除此之外,我有点迷路了。非常感谢如果有人想知道的话,我会解决的
$("#txtReservePrice").rules("add", {greaterThanStartPrice:"#txtStartPrice"});