2015-02-11 124 views
0

我創建了一個過濾器,根據比較選定的值從表中刪除行。問題是我需要在用戶選擇不同的值後顯示刪除的行,但我不知道如何。 這是我的函數:顯示刪除後使用jQuery和下拉選擇行

$(document).ready(function() { 
    $("button").click(function() { 
     $("td").each(function(index, paragraph) { 
      $td = $(paragraph); 
      if ($td.html() === $('select[name=select1]').val()) { 
       $(this).parent("tr:first").remove();     } 
     }); 
}); 

,這是下拉菜單:

<select name="select1"> 
    <option value="" disabled selected>user name</option> 
    <?php while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { ?> 
     <option value="<?php echo $line['user_name'];?>"> 
      <?php echo $line['user_name'];?> 
     </option> 
    <?php } ?> 
</select> 

是否有辦法後select1變化我可以返回刪除行的表?

+1

這聽起來像你不想「刪除」行這麼多的「隱藏」他們。 – JRulle 2015-02-11 15:41:43

回答

0

你爲什麼不只是改變了TR的CSS:

display: none; 

而不是刪除呢?然後你就可以將其更改爲回添加:

display: block; 
0

而不是刪除匹配的行,爲什麼不躲他們,然後再次顯示所有行每當下拉值被改變?

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

JSFIDDLE Demo

相關問題