2016-02-04 34 views
0

我遇到了让它工作的问题。这里此代码的工作:在jQuery中使用&& if语句

if ($('.test').is(':visible')) { 
    if ($('.test').val() >= 1)) { 
     $(".test .section").show(); 
     $("#something").hide(); 
    } else { 
     $(".test .section").hide(); 
    } 
} 

但是当我尝试添加& &运营商指定范围,我得到一个错误说,它不是一个功能:

if ($('.test').is(':visible')) { 
    if ($('.test').val() >= 1 && ('.test').val() <= 100)){ 
     $(".test .section").show(); 
     $("#something").hide(); 
    } else { 
     $(".test .section").hide(); 
    } 
} 

我已经试过这以及:

if ($(('.test').val() >= 1) && (('.test').val() <= 100))) 

我想不通这是行不通的。

+6

您在第2'( '测试')。VAL()忘了'$'' – Stryner

+1

有($('。test')。val()> = 1 &&('.test')。val()<= 100))' – LostMyGlasses

+0

我用$('。test)试过了。 val <= 100) – Keith

回答

1

if(($('.test').val() >= 1) && ($('.test').val() <= 100)) 

您有一个额外的),并需要添加$