请查看此代码,并告诉我为什么即使我的错误确实被触发,我的错误变量仍然尖叫 0。我已经尝试并尝试让它们改变。我只是在这一点上迷路了。
validationError = 0;
$("#step1continue").click(function(){
var fname = $('#fname');
if (fname.val() == "") {
fname.addClass("needsfilled");
fname.val('Required!');
validationError = 1;
} else {
validationError = 0;
}
var lname = $('#lname');
if (lname.val() == "") {
lname.addClass("needsfilled");
lname.val('Required!');
validationError = 1;
} else {
validationError = 0;
}
var company_name = $('#company_name');
if (company_name.val() == "") {
company_name.addClass("needsfilled");
company_name.val('Required!');
validationError = 1;
} else {
validationError = 0;
}
var email = $('#email');
if (email.val() == "") {
email.addClass("needsfilled");
email.val('Required!');
validationError = 1;
} else {
validationError = 0;
}
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if (!emailReg.test(email.val())) {
email.addClass("needsfilled");
email.val('Use a real email address!');
validationError = 1;
} else {
validationError = 0;
}
var phone = $('#phone');
if (phone.val() == "") {
phone.addClass("needsfilled");
phone.val('Required!');
validationError = 1;
} else {
validationError = 0;
}
if (phone.val().length < 10) {
phone.addClass("needsfilled");
phone.val('10 digits minimum');
validationError = 1;
} else {
validationError = 0;
}
var phoneregxp = /^[0-9]$/;
if (phoneregxp.test(phone.val())) {
phone.addClass("needsfilled");
phone.val('Numbers ONLY');
validationError = 1;
} else {
validationError = 0;
}
alert(validationError);
});