我想用jQuery驗證輸入字段。我想檢查該字段的val();
爲5個以上,或者如果該字段的值小於2jQuery - 如果語句,結合兩個IF的
目前,這是我有:
$('#customamount').keyup(function() {
$('.amount-field').text($(this).val());
if($(this).val() > 5){
$(this).addClass("error");
$(this).prop("title","Whoops! Too high");
$(this).tooltip('toggle');
}else{
$(this).removeClass("error").addClass("success");
$(this).attr("title","Good!");
$(this).tooltip('toggle');
}
if($(this).val() < 2){
$(this).addClass("error");
$(this).prop("title","The minimum amount is 2.");
$(this).tooltip('toggle');
}else{
$(this).removeClass("error").addClass("success");
$(this).attr("title","Good!.");
$(this).tooltip('toggle');
}
});
<input type="text" value="10" id="customamount">
目前,它只是將.success
類添加到輸入和title="Good!"
如何組合上述兩個IF語句?
這是非常基本的編程曲estion – 2014-09-02 13:35:45
@nagarajub我是jQuery編程新手 - 認爲我可以在這裏獲得一些幫助,儘管它對於大多數人來說是基本的。 – oliverbj 2014-09-02 13:38:52
嘿,你有良好的聲譽(782),解決了很多問題,你怎麼會錯過這個簡單的編程邏輯 – 2014-09-02 13:41:45