簡體   English   中英

捕獲提交適用於Firefox但不適用於Chrome

[英]Catching the Submit works in Firefox but not in Chrome

我正在使用它來按下提交按鈕,驗證所有內容,然后停止或讓它通過,這適用於Firefox,但不適用於Chrome,Chrome允許表單空白。 我還有一個重置功能,可以在Chrome中運行但在Firefox中。 我是js和jquery的新手,並且可以使用一些幫助來解決這個問題,因為在一個瀏覽器中工作的東西而不是另一個混​​淆了我的問題:)

(抱歉我的測試警報仍然存在)

這是代碼:

$("form").submit(function(e){
if (e.originalEvent.explicitOriginalTarget.id=="btn") {

if (bizNameValid==false || bizWebValid==false || bizStreetValid==false || bizCityValid==false || bizStateValid==false || bizZipValid==false || bizPhoneValid==false || firstValid==false || lastValid==false || custStreetValid==false || custCityValid==false || custStateValid==false || custZipValid==false || custPhoneValid==false || custEmailValid==false || monValid==false || yearValid==false || typeValid==false || ccValid==false) {
alert("bizNameValid:" + bizNameValid+"\n bizWebValid:"+bizWebValid+"\n bizStreetValid"+bizStreetValid +"\n bizCityValid: "+bizCityValid+ "\n bizStateValid:"+bizStateValid+"\n bizZipValid: "+bizZipValid+"\n bizPhoneValid:"+bizPhoneValid+"\n firstValid:"+firstValid+"\n lastValid:"+lastValid+"\n custStreetValid:"+custStreetValid+"\ncustCityValid"+custCityValid+"\n custStateValid"+custStateValid+"\n custZipValid:"+custZipValid+"\n custPhoneValid"+custPhoneValid+"\n custEmailValid:"+custEmailValid+"\n monValid:"+monValid+"\n yearValid:"+yearValid +"\n ccValid:"+ccValid+" \nccType:"+typeValid);
e.preventDefault();
return false;

}
else if(total==0) {
$("#svc_desc").append("</br><label id='first_error' style='font-size:16pt;'>You must select a service to continue</label>");
alert("You must select a service to continue");
e.preventDefault();
return false;
}
else {
return true;
}
}
});

嘗試

$("form").submit(function(e){
    var target = e.originalEvent || e.originalTarget;

    if($(target.srcElement || target.originalTarget).attr('id')=="btn"){

    }
    //rest of  your code 


});

參考: https//stackoverflow.com/a/8067990/1679410

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM