首先,您的代码包含错误,因为您缺少}
. validateForm
其次,单击按钮时不要调用join
。
$('#join').click(function () {
var correct = true;
var validEmail = true;
$('input[type="text"]').each(function (indx) {
var $currentField = $(this);
if ($currentField.val() === '') {
$currentField.addClass('empty');
correct = false;
$currentField.one('keydown', function () {
$currentField.removeClass('empty');
});
} else {
$currentField.removeClass('empty');
}
});
function validateForm() {
var x = document.forms["signup"]["email"].value;
var atpos = x.indexOf("@");
var dotpos = x.lastIndexOf(".");
if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= x.length) {
correct = false;
validEmail = false;
}
}
validateForm();
if (correct) {
$('#answer').html('Thank You!');
setTimeout(function () {
$('.inputs').hide("slide", { direction: "up" }, 1000);
}, 2000);
} else {
if(validEmail)
$('#answer').html('Please fill highlighted fields.');
else
$('#answer').html('Not a valid email');
}
});