我有以下代码正常工作:
success: function (upd_rsp){
//if email is not register
if(upd_rsp == "email_no"){
exstInfo.text("This E-mail is not registered in our Database!");
exstInfo.addClass("error");
return false;
}
//if email & pass don't match
if(upd_rsp == "email_pass_no"){
matchInfo.text("Email and Password don't match!");
matchInfo.addClass("error");
return false;
}
现在,如果我放在那些2"如果"一个"否则"声明(下),第二个" if"没有被执行。我哪里错了?
else{
exstInfo.text("");
exstInfo.removeClass("error");
return true;
}
解决方案效果很好。
答案 0 :(得分:2)
如果您在执行第二个return
之前设置了if
值,则在return
发送后脚本将停止。
这是您可以采取的众多方法之一:
success: function (upd_rsp){
//if email is not register
var email_error = false;
var pass_error = false;
if(upd_rsp == "email_no"){
exstInfo.text("This E-mail is not registered in our Database!");
exstInfo.addClass("error");
email_error = true;
} else {
exstInfo.text("");
exstInfo.removeClass("error");
email_error = false;
}
//if email & pass don't match
if(upd_rsp == "email_pass_no"){
matchInfo.text("Email and Password don't match!");
matchInfo.addClass("error");
pass_error = true;
} else {
....
pass_error = false;
}
if(email_error == true || pass_error == true){
return false;
} else {
return true;
}