我在下面的代码中遇到问题,如果我在其中输入了无效的电子邮件地址,它将第一次正确显示 signUpWarning 警报,但如果我关闭该框并尝试相同的无效电子邮件,它将不会弹出。有任何想法吗?
$(document).ready(function() {
//if submit button is clicked
$('#submit_btn').click(function(e) {
e.preventDefault();
var email = $('#email').val();
if (!is_valid_email(email)){
$("#signUpWarning").show();
}else{
$.ajax({
url: "process.php",
type: "post",
data: "email=" + email,
success: function() {
$("#signUpWarning").hide();
$("#signUpAlert").show();
}
});
}
});
});
function is_valid_email (email)
{
return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);
}
警告框的代码是:
<div class="alert alert-block alert-error hide" id="signUpWarning"><!--Use: $("#signUpWarning").show(); to show this alert-->
<a class="close" data-dismiss="alert">×</a>
<h5 class="alert-heading">Sorry!</h5> Your e-mail address was not valid, please try again.
</div>