0

我有以下工作正常的代码:

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;
  }

现在,如果我在这两个“if”之间放置一个“else”语句(如下),则第二个“if”不会被执行。我哪里错了?

   else{
   exstInfo.text("");
   exstInfo.removeClass("error");
   return true;
   }

解决方案工作得很好。

4

1 回答 1

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;
  }
于 2012-07-16T12:52:47.720 回答