我为 jQuery Validation 编写了以下简单规则:
jQuery.validator.addMethod("notEqual", function(value, element, param)
{
return this.optional(element) || value != param;
}, "This field is required");
这样我可以说:
$("#form").validate({
rules:
{
field1: {notEqual: "Please Select", required: true},
field2: {notEqual: "Year", required: true}
},
messages:
{
field1: {
notEqual: "This field is required",
required: "This field is required"
}
field2: {
notEqual: "This field is required",
required: "This field is required"
}
},
submitHandler: function(form) {
form.submit();
}
});
但是我想说任何一个字段都不允许等于多个事物,例如
field1: {notEqual: "Please Select" || "Year" || "Some Value", required: true},
但是我已经尝试过这种语法以及其他一些排列“ÖR”运算符的方法,但它们都不起作用。任何人都可以帮忙吗?谢谢。