jQuery Validation插件自定义方法.多个参数 [英] jQuery Validation plugin custom method. Multiple parameters

查看:151
本文介绍了jQuery Validation插件自定义方法.多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将自定义验证器与jQuery Validation插件一起使用. 但是,我不确定如何将多个参数传递给验证方法? 我尝试使用(2,3),花括号和组合键,但失败了.

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 using (2,3), curly braces and combinations, but I have failed.

这是代码-????标记我需要以下信息的区域:

This is the code - ???? marks the area I need info about:

$(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数组:

Javascript arrays:

[value1,value2,value3]

所以您的代码可能是:

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

这篇关于jQuery Validation插件自定义方法.多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆