這個錯誤使我瘋狂,一切似乎都是爲了,但希望我錯過了簡單的東西。jQuery驗證無法調用未定義的方法「調用」
代碼在我的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
}
}
});
定製驗證
$.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."
);
基本上問題是自定義的驗證之外,但是我把他們在這裏反正...形式驗證罰款時,提交,但有幾個'房屋號碼'和'街道',試圖填補他們時,會拋出此錯誤。
例如,我提交表單與一個空的街道n棕褐色,驗證工作,但是當我填寫輸入,在模糊這個錯誤被拋出。
的錯誤是在jquery.validate這裏的var rule = { method: method, parameters: rules[method] }
行:
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;
}
}
預先感謝任何指針
爲了更好地使用indexOf而不是=== –
if(result.indexOf(「dependency-mismatch」)> -1) –
還要通過移除ContentPlace持有者來更改您的選擇器...類似這樣的事情而不是'ctl00 $ SecondaryPlaceHolder $ txPayloadDate'做這個'[id * = txPayloadDate]' –