我试图在http://jqueryvalidation.org/reference/中实现“重构规则”部分
但问题是,我不知道在哪里放置 $.validator 代码。现在,我正在添加
// alias required to cRequired with new message
$.validator.addMethod("cRequired", $.validator.methods.required,
"Customer name required");
// alias minlength, too
$.validator.addMethod("cMinlength", $.validator.methods.minlength,
// leverage parameter replacement for minlength, {0} gets replaced with 2
$.format("Customer name must have at least {0} characters"));
// combine them both, including the parameter for minlength
$.validator.addClassRules("customer", { cRequired: true, cMinlength: 2 });
文件加载后,但它似乎不起作用。接下来,我尝试将它添加到 jquery validate javascript 文件本身,但没有运气。任何帮助表示赞赏。