jQuery Validate无法调用未定义的方法’call’

前端之家收集整理的这篇文章主要介绍了jQuery Validate无法调用未定义的方法’call’前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这个错误让我疯狂,一切似乎都井然有序,但希望我错过了一些简单的事情.

我的aspx中的代码

$('#myForm').validate({
            rules: {
                'ctl00$SecondaryPlaceHolder$txPayloadDate': {
                    required: true,date: true
                },'ctl00$SecondaryPlaceHolder$ddlMapPlat': {
                    required: true
                },'ctl00$SecondaryPlaceHolder$txtBlock': {
                    maxLength: 3
                },'ctl00$SecondaryPlaceHolder$txtLeakNumber': {
                    number: true,maxLength: 27
                },'ctl00$SecondaryPlaceHolder$txtHouseNumber': {
                    required: true,maxLength: 10,},'ctl00$SecondaryPlaceHolder$txtStreet': {
                    required: true,maxLength: 100
                },'ctl00$SecondaryPlaceHolder$txtCity': {
                    required: true,maxLength: 50
                },'ctl00$SecondaryPlaceHolder$txtReading': {
                    isPositiveInteger: true,'ctl00$SecondaryPlaceHolder$ddlInfoCodes': {
                    existsWithLowReading: true
                },'ctl00$SecondaryPlaceHolder$txtLocationRemarks': {
                    maxLength: 500
                },'txtGrade2RequestedRepairDate': {
                    date: true
                },'ctl00$SecondaryPlaceHolder$ddlEquipment': {
                    required: true
                }
            }
        });

自定义验证

$.validator.addMethod("isPositiveInteger",function (value,element) {
        if($.trim(value) !== '')
            return /^\d+$/.test(value);
        return true;
    },"Must be a valid integer."
);


$.validator.addMethod("existsWithLowReading",element) {
        if (parseFloat($('#SecondaryPlaceHolder_txtReading').val() <= 2) && value.length < 1) {
            return false;
        }
        return true;
    },"Info Code required if Reading % is less than three."
);

基本上这个问题不在自定义验证之内,但我还是把它们扔到这里……表单在提交时验证正常,但是有一些’门牌号’和’街道’在尝试填写它们时会抛出此错误在.

例如,我提交一个空的街道号码表格,验证工作,但当我填写输入时,模糊这个错误被抛出.

错误在jquery.validate这里的var rule = {method:method,parameters:rules [method]} line:

check: function (element) {
            element = this.validationTargetFor(this.clean(element));

            var rules = $(element).rules();
            var dependencyMismatch = false;
            var val = this.elementValue(element);
            var result;

            for (var method in rules) {
                var rule = { method: method,parameters: rules[method] };
                try {

                    result = $.validator.methods[method].call(this,val,element,rule.parameters);

                    // if a method indicates that the field is optional and therefore valid,// don't mark it as valid when there are no other rules
                    if (result === "dependency-mismatch") {
                        dependencyMismatch = true;
                        continue;
                    }
                    dependencyMismatch = false;

                    if (result === "pending") {
                        this.toHide = this.toHide.not(this.errorsFor(element));
                        return;
                    }

                    if (!result) {
                        this.formatandAdd(element,rule);
                        return false;
                    }
                } catch (e) {
                    if (this.settings.debug && window.console) {
                        console.log("exception occured when checking element " + element.id + ",check the '" + rule.method + "' method",e);
                    }
                    throw e;
                }
            }

提前感谢任何指针

解决方法

我这个愚蠢的错字是罪魁祸首

maxLength不是骆驼套装,应该是maxlength

虽然相同的东西是骆驼套装……似乎不一致,但很高兴我弄清楚了

原文链接:https://www.f2er.com/jquery/178687.html

猜你在找的jQuery相关文章