我正在使用它来按下提交按钮,验证所有内容,然后停止或让它通过,这适用于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;
}
}
});
答案 0 :(得分:2)
试
$("form").submit(function(e){
var target = e.originalEvent || e.originalTarget;
if($(target.srcElement || target.originalTarget).attr('id')=="btn"){
}
//rest of your code
});