[英]Why is this jQuery Validation not working on IE 7/8?
我遇到了一個客戶端驗證腳本的小問題,該腳本可在包括IE 9/10在內的所有瀏覽器上運行,但讓我頭疼IE 7和IE 8。
可以在此處訪問帶有需要驗證的表單的頁面,必須有人明確地看一下才能給出良好的答案。
這是我用於表單的驗證腳本:
jQuery(document).ready(function(){
jQuery("#adaugareanunt").submit(function(event){
errornotice = jQuery("#eroareadaugare");
emptyerror = "Necompletat";
emailerror = "Email incorect";
email = jQuery('#contactEmail');
descriere = jQuery('#descriptionro_RO');
jQuery('#adaugareanunt input[type="text"]').each(function(){
if ((jQuery(this).val() == "") || (jQuery(this).val() == emptyerror)) {
jQuery(this).addClass("campuri-necesare");
jQuery(this).val(emptyerror);
errornotice.fadeIn(750);
} else {
jQuery(this).removeClass("campuri-necesare");
}
});
jQuery('#adaugareanunt select').each(function(){
if ((jQuery(this).val() == "")) {
jQuery(this).addClass("campuri-necesare");
errornotice.fadeIn(750);
} else {
jQuery(this).removeClass("campuri-necesare");
}
});
if(descriere.val() == "" || descriere.val() == emptyerror) {
descriere.addClass("campuri-necesare");
descriere.val(emptyerror);
errornotice.fadeIn(750);
} else {
descriere.removeClass("campuri-necesare");
}
if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.val())) {
email.addClass("campuri-necesare");
email.val(emailerror);
}
if (jQuery(":input").hasClass("campuri-necesare")) {
return false;
}
});
// Clears any fields in the form when the user clicks on them
jQuery(":input").focus(function(){
if (jQuery(this).hasClass("campuri-necesare") ) {
jQuery(this).val("");
jQuery(this).removeClass("campuri-necesare");
}
});
});
有什么提示嗎?
謝謝!
丹·卡皮坦·德普拉
您的JavaScript檔案似乎有誤
未捕獲到的TypeError:無法在行號291上的adaugare_anunt.js上調用未定義的方法“ addMethod”,請首先解決該錯誤,因為通常在IE8和更低版本中,當javascript遇到錯誤時,所有javascript均無法正常工作。
請使用ie IE9,然后按f12鍵將瀏覽器模式更改為ie8並開始調試。
希望這對您有所幫助。謝謝Madhu Rakhal Magar
Frits Van Campen給了我一個提示,我發現了錯誤。 在定義每個變量之前,我必須添加var
文本。 現代瀏覽器沒有看到要求的東西,但是較舊的瀏覽器會要求它。
謝謝!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.