我有这两种方法,它们工作,有点...
问题在于,在第一种情况下,只有具有该类名的第一个输入项有效。
$.validator.addClassRules("NameField",{
required: true,
minlength: 2,
uniqueName: {
product: function() {
return $(this).val();
}
},
messages: {
required: "Required Field",
minlength: "Minimum 2 characters",
uniqueName: "Name exists already",
remote: ''
}
});
第二个示例的问题是验证有效,但消息不适用于远程验证器
$(".NameField").rules("add", {
required: true,
minlength: 2,
uniqueName: {
product: function() {
return $(this).val();
}
},
messages: {
required: "Required Field",
minlength: "Minimum 2 characters",
uniqueName: "Name exists already",
remote: ''
}
});
这是验证器的代码
$.validator.addMethod("unique", function(value, element, params) {
return $.validator.methods.remote.call(this, value, element, {
url: 'mypage',
data: {
: value
}
});
});
有什么想法吗?