我正在尝试将自定义验证器与 jQuery 验证插件一起使用。 但是,我不确定您应该如何将多个参数传递给验证方法? 我尝试过使用 (2,3)、花括号和组合,但失败了。
这是代码 - ????标记我需要相关信息的区域:
$(document).ready(function() {
jQuery.validator.addMethod("math", function(value, element, params) {
return this.optional(element) || value == params[0] + params[1];
}, jQuery.format("Please enter the correct value for {0} + {1}"));
$("#form_register").validate({
debug: true,
rules: {
inputEl: { required: true, math: ???? }
},
messages: {
inputEl: { required: "Required", math: "Incorrect result" }
}
});
});
最佳答案
Javascript 数组:
[value1,value2,value3]
所以你的代码可能是:
inputEl: { required: true, math: [2, 3 ,4 , 5] }
关于jQuery 验证插件自定义方法。多个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1366858/