使用Filter Table在第一个td上执行例外

时间:2017-12-05 23:37:11

标签: javascript jquery html twitter-bootstrap

他想要一个带有过滤表选项的输入框。 我的输入框是:

   $data = '<table class="table table-bordered table-striped">
                                            <tr>
                                                    <th>No.</th>
                                                    <th>Status</th>
                                                    <th>First Name</th>
                                                    <th>Last Name</th>
                                                    <th>Email Address</th>
                                                    <th>Update</th>
                                                    <th>Delete</th>
                                            </tr>';
    $query = "SELECT * FROM users";

和这段代码生成一个表:

$(document).ready(function(){
  $("#myInput").on("keyup", function() {
    var value = $(this).val().toLowerCase();
    $("#myTable tr").filter(function() {
      $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
    });
  });
});

我的js是:

base

是否有必要使用tbody或其他任何东西来做过滤表? 是否可以为第一个做例外?

非常感谢!

2 个答案:

答案 0 :(得分:0)

是的,可以为第一个做例外。尝试类似:

$('table tr:gt(1)').filter...

(你的标题有1行,所以它会起作用)

答案 1 :(得分:0)

我做到了!

最后使用此代码:

$(function(){
    $("#myInput").on("keyup", function() {
        var $value = $(this).val().toLowerCase();
        $("#myTable tr:gt(0)").filter(function() {
            $(this).toggle($(this).text().toLowerCase().indexOf($value) > -1)
        });
    });
});