jQuery验证插件自定义方法 多个参数

前端之家收集整理的这篇文章主要介绍了jQuery验证插件自定义方法 多个参数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图使用jQuery验证插件自定义验证器。
但是,我不确定你应该如何将多个参数传递给验证方法
我试过使用(2,3),花括号和组合,但我失败了。

这是代码 – ????标记我需要的信息:

  1. $(document).ready(function() {
  2. jQuery.validator.addMethod("math",function(value,element,params) {
  3. return this.optional(element) || value == params[0] + params[1];
  4. },jQuery.format("Please enter the correct value for {0} + {1}"));
  5.  
  6. $("#form_register").validate({
  7. debug: true,rules: {
  8. inputEl: { required: true,math: ???? }
  9. },messages: {
  10. inputEl: { required: "required",math: "Incorrect result" }
  11. }
  12. });
  13. });

解决方法

Javascript数组:
  1. [value1,value2,value3]

所以你的代码可能是:

  1. inputEl: { required: true,math: [2,3,4,5] }

猜你在找的jQuery相关文章