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, maxLength: 100 }, 'ctl00$SecondaryPlaceHolder$ddlInfoCodes': { existsWithLowReading: true }, 'ctl00$SecondaryPlaceHolder$txtLocationRemarks': { maxLength: 500 }, 'txtGrade2RequestedRepairDate': { date: true }, 'ctl00$SecondaryPlaceHolder$ddlEquipment': { required: true } } }); 

自定义validation

 $.validator.addMethod("isPositiveInteger", function (value, element) { if($.trim(value) !== '') return /^\d+$/.test(value); return true; }, "Must be a valid integer." ); $.validator.addMethod("existsWithLowReading", function (value, element) { if (parseFloat($('#SecondaryPlaceHolder_txtReading').val() <= 2) && value.length < 1) { return false; } return true; }, "Info Code required if Reading % is less than three." ); 

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

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

错误在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

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