2016-01-24 13 views
2
<select> 
<option>1</option> 
<option>3</option> 
<option>5</option> 
<option>10</option> 
<option>35</option> 
</select> 

我已經得到了以下的工作代碼,刪除所有選擇選項,其中選項的文本少於5之間:刪除選擇的選項,其中的文字是不是兩個值

$("#filter-group5 select option").filter(function(){ 
    return $.trim($(this).text()) < 5;  
}).remove(); 

我如何修改刪除不在兩個整數之間的所有選項的代碼(5,30)?

我試過如下:

$("#filter-group5 select option").filter(function(){ 
     return $.trim($(this).text()) < 5 && $.trim($(this).text()) > 30;  
}).remove(); 

但它不工作。沒有任何反應,所有選項依然存在,即使是那些5。

回答

3
  1. 您需要將innerText解析爲數字。
  2. 使用||或代替'& &。

代碼:

$("#filter-group5 select option").filter(function(){ 
    return +$(this).text() < 5 || +$.trim($(this).text() > 30;  
}).remove(); 
相關問題