2015-02-11 40 views
-2

我能隱藏行匹配這樣的值:選擇所有除「這個」 jQuery中

$(document).ready(function() { 
    $('select[name=select1]').change(function() { 
     $("td").each(function(index, paragraph) { 
      $td = $(paragraph); 
      if ($td.html() === $('select[name=select1]').val()) { 
       //hide the matched row rather than remove it 
       $(not(this)).parent("tr:first").hide(); 
      } 
     }); 
     $('select[name="select1"]').on('change', function() { 
      $("tr").show(); 
     }); 
    }); 
}); 

我到底做錯了什麼?

+0

你爲初學者嵌套了兩個'change'事件處理程序。這絕不是一個好主意。請展示您的HTML示例,以便將代碼放在透視圖中。 – 2015-02-12 11:04:31

回答

1

我不知道你的html標記,但只是隱藏所有元素,並「取消隱藏」你不想隱藏的元素。

if ($td.html() === $('select[name=select1]').val()) { 
    //hide the matched row rather than remove it 
    $('tr').hide(); 
    $(this).parent("tr:first").show(); 
}