Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/428.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery验证addClassRules返回NaN而不是最大值_Javascript_Jquery_Validation_Coffeescript - Fatal编程技术网

Javascript jQuery验证addClassRules返回NaN而不是最大值

Javascript jQuery验证addClassRules返回NaN而不是最大值,javascript,jquery,validation,coffeescript,Javascript,Jquery,Validation,Coffeescript,我用类“age”为我的元素制定了一个自定义验证规则(注意:我知道我可以使用name属性制定一个基本规则,但这不是我在这里想要的) 我的代码如下所示(CoffeeScript): 当我在Chrome控制台中尝试parseInt($('#max_age').data('max'),10)时,它返回正确的值,经过完美解析 但是,我的验证规则似乎不起作用…我的输入“.age”中出现错误“请输入一个小于或等于NaN的值” 总之,验证规则适用于'required'和'min',但我似乎无法为'max'参数使

我用类“age”为我的元素制定了一个自定义验证规则(注意:我知道我可以使用name属性制定一个基本规则,但这不是我在这里想要的)

我的代码如下所示(CoffeeScript):

当我在Chrome控制台中尝试
parseInt($('#max_age').data('max'),10)
时,它返回正确的值,经过完美解析

但是,我的验证规则似乎不起作用…我的输入“.age”中出现错误“请输入一个小于或等于NaN的值”

总之,验证规则适用于'required'和'min',但我似乎无法为'max'参数使用自定义值

有人知道吗?我检查了,但他们在示例中只使用数值

非常感谢

这应该会有帮助

在您的验证js中

改变

// clean number parameters
$.each(['minlength', 'maxlength', 'min', 'max'], function() {
    if (rules[this]) {
        rules[this] = Number(rules[this]);
    }
});

  // clean number parameters
    $.each(['minlength', 'maxlength'], function() {
        if (rules[this]) {
            rules[this] = Number(rules[this]);
        }
    });
否则,请使用最新版本升级您的验证js

资料来源:

  // clean number parameters
    $.each(['minlength', 'maxlength'], function() {
        if (rules[this]) {
            rules[this] = Number(rules[this]);
        }
    });