這裏是我的驗證代碼:使表單驗證返回true?
function validateEnquiryForm() {
var x = document.forms["enquiry"]["name"].value;
if(x == null || x == "" || x == "Name") {
$('#name').removeClass('custom').addClass('error');
$('.name-error').show();
//return false;
} else if(x !== null || x !== "" || x !== "Name") {
$('#name').removeClass('error').addClass('custom');
$('.name-error').hide();
}
var x = document.forms["enquiry"]["phone"].value;
if(x == null || x == "" || x == "Phone Number") {
$('#phone').removeClass('custom').addClass('error');
$('.phone-error').show();
//return false;
} else if(x !== null || x !== "" || x !== "Phone Number") {
$('#phone').removeClass('error').addClass('custom');
$('.phone-error').hide();
}
var x = document.forms["enquiry"]["requirements"].value;
if(x == null || x == "" || x == "Add any other extra requirements here...") {
$('#requirements').removeClass('textarea-1').addClass('error');
$('.requirements-error').show();
//return false;
} else if(x !== null || x !== "" || x !== "Add any other extra requirements here...") {
$('#requirements').removeClass('error').addClass('custom');
$('.requirements-error').hide();
}
var x = document.forms["enquiry"]["summary"].value;
if(x == null || x == "" || x == "Summarise your project in a few key words...") {
$('#summary').removeClass('custom').addClass('error');
$('.summary-error').show();
//return false;
} else if(x !== null || x !== "" || x !== "Summarise your project in a few key words...") {
$('#summary').removeClass('error').addClass('custom');
$('.summary-error').hide();
}
var x = document.forms["enquiry"]["email"].value;
var atpos = x.indexOf("@");
var dotpos = x.lastIndexOf(".");
if(atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= x.length) {
$('#email').removeClass('custom').addClass('error');
$('.email-error').show();
//return false;
} else if(atpos > 1 || dotpos > atpos + 2 || dotpos + 2 <= x.length) {
$('#email').removeClass('error').addClass('custom');
$('.email-error').hide();
}
$('.error-banner').effect("pulsate", {
times: 2
}, 1000);
return false;
}
當代碼運行時,它會檢查所有的領域,看看他們是空白。如果.error-banner
脈衝中有一個或多個填充不正確並顯示單個消息。問題是當表單填寫正確時,此橫幅仍然閃爍。有人能告訴我我要去哪裏嗎??
那麼函數**總是**返回'false'。你如何期待它做別的事情? – Pointy 2012-07-07 14:41:49
此外,jQuery與'document.forms'的奇怪組合是......奇怪的。 – Pointy 2012-07-07 14:42:15
聽說過數據結構和代碼可讀性嗎? – Engineer 2012-07-07 14:42:34