我正在測試由我自己的兩個領域驗證。當他們空了,我想顯示一條消息。「如果」條件JQuery的 - 驗證空字段
問題是「如果」條件沒有正確執行,我不知道爲什麼。
這是HTML代碼:
<div id="switchingform">
<label for="currentsupplier">Who is your current supplier?</label>
<input type="text" name="currentsupplier" id="currentsupplier"/><br />
<span class="validateText" id="validateSupplier"><p>Please enter your current supplier</p></span>
<label for="postcode">What is your post code?</label>
<input type="text" name="postcode" id="postcode"/><br />
<span class="validateText" id="validatePostCode"><p>Please enter your post code</p></span>
</div>
這是jQuery代碼:
$("#telecomBusNext").click(function(){
if($("#currentsupplier").val().length < 1 || $("#postcode").val().length < 1) {
$("#validateSupplier").fadeIn(400);
$("#validatePostCode").fadeIn(400);
return false;
} else if($("#currentsupplier").val().length > 1 || $("#postcode").val().length < 1) {
$("#validatePostCode").fadeIn(400);
$("#validateSupplier").fadeOut(400);
return false;
} else if($("#currentsupplier").val().length < 1 || $("#postcode").val().length > 1) {
$("#validatePostCode").fadeOut(400);
$("#validateSupplier").fadeIn(400);
return false;
} else {
$("#validateSupplier").fadeOut(400);
$("#validatePostCode").fadeOut(400);
}
});
在此先感謝。
你能定義'不工作'嗎? –
用'&&'更改'||',它應該可以工作。你在兩個不同的條件中定義了兩個相同的條件。你的邏輯是錯誤的。 –
你顯然不明白'||'和'&&'之間的區別。這對程序員來說是一個非常基本的誤解。 – Barmar