我正在尝试实施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文件本身,但是没有运气。任何帮助表示赞赏。

最佳答案

查看Github source,然后尝试使用记录的examples

基本上看起来,您应该在将插件包含在html文件中之后立即放置代码。

10-02 10:17