我在“通过”表单验证器的验证时遇到问题,它停止并且不会开始处理。当它应该被处理它给我“你需要填写:”
有什么问题?
查询:
$("form").submit(function (e) {
e.preventDefault(); // This will prevent the form submission
var response = "";
var missing = "";
$('#submit-holder').find('input').each(function(){
if ($(this).val() == '') {
missing += $('label[for="' + this.id + '"]').html() + " | ";
empty_fields = true;
missing_fields = true;
}
else if ($(this).val() != '') {
empty_fields = false;
$('.alert').hide();
}
});
response += "* <strong>You need to fill out:</strong> " + missing;
if(!$('#user_terms').is(':checked'))
{
response += "<br>* You need to accept the terms and conditions to continue";
}
var email = $('[name="txtEmail"]').val();
if(IsEmail(email)==false){
valid_email = false;
response += "<br><strong>* The e-mail address you've entered is invalid</strong>";
}
response_message(response);
if(!missing_fields && valid_email !== false && $('#user_terms').is(":checked")) {
$('.alert').hide()
}
});
// Functions:
function IsEmail(email) {
var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if(!regex.test(email)) {
return false;
}else{
return true;
}
}
function response_message(response) {
$('.alert').addClass('alert-danger');
$('.alert').fadeIn();
$('.error_message').html(response);
}