0
請看這段代碼,並告訴我爲什麼即使當我的錯誤得到觸發,我的錯誤變量仍然尖叫0。爲什麼我試圖嘗試並試圖讓他們改變。我現在只是迷失了。Jquery變量沒有更新?
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-\.][email protected]([\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);
});
到底是什麼我打字,直到'新答案'警報彈出;) –
哦太棒了!實際上只是使用了你所說的關於一遍又一遍的重置並簡單地刪除了0。在「點擊」功能期間,如果即使只設置了1,它也應該停止移動到第2步的能力,這樣你的回答就完美了! –