jQuery Validation plugin custom method. Multiple parameters

后端 未结 2 1529
野性不改
野性不改 2020-12-29 20:49

I\'m trying to use a custom validator with jQuery Validation plugin. However, I\'m unsure how are you supposed to pass multiple arguments to a validation method? I\'ve tried

相关标签:
2条回答
  • 2020-12-29 21:07

    Javascript arrays:

    [value1,value2,value3]
    

    SO your code might be:

    inputEl: { required: true, math: [2, 3 ,4 , 5] }
    
    0 讨论(0)
  • 2020-12-29 21:30

    You can also pass a normal JavaScript object as a parameter which I personally find easier to work with:

    jQuery.validator.addMethod("myRule", function (value, element, options) {
        return value === options.data;
    }, "My Rule says no!");
    
    $("#input").rules("add", { myRule: { data: "foo" } });
    
    0 讨论(0)
提交回复
热议问题