使用remote
规则时,请参阅文档以获取示例:
http://docs.jquery.com/Plugins/Validation/Methods/remote#options
该remote
规则用于将特定字段的内容与您的数据库进行比较……例如检查名称或密码是否已经存在。它不能用于简单地将错误消息列表转储回插件。就插件而言,您只是为一条规则设置一条错误消息。见:http: //jsfiddle.net/zga8y/
我真的不明白你想要做什么的目的。通常,每个规则的错误消息设置一次并且不会更改。
要动态更改特定字段上的消息,您可以使用rules('add')
方法. 您甚至不必触碰规则即可覆盖消息。
$("#myinput").rules("add", {
messages: {
required: "Required input",
minlength: jQuery.format("Please, at least {0} characters are necessary")
}
});
或者,您可以覆盖任何或所有消息,如下所示:
jQuery.extend(jQuery.validator.messages, {
required: "This field is required.",
remote: "Please fix this field.",
email: "Please enter a valid email address.",
url: "Please enter a valid URL.",
date: "Please enter a valid date.",
dateISO: "Please enter a valid date (ISO).",
number: "Please enter a valid number.",
digits: "Please enter only digits.",
creditcard: "Please enter a valid credit card number.",
equalTo: "Please enter the same value again.",
accept: "Please enter a value with a valid extension.",
maxlength: jQuery.validator.format("Please enter no more than {0} characters."),
minlength: jQuery.validator.format("Please enter at least {0} characters."),
rangelength: jQuery.validator.format("Please enter a value between {0} and {1} characters long."),
range: jQuery.validator.format("Please enter a value between {0} and {1}."),
max: jQuery.validator.format("Please enter a value less than or equal to {0}."),
min: jQuery.validator.format("Please enter a value greater than or equal to {0}.")
});