筛选Jquery表的第一列

Filter First column of table Jquery

本文关键字:一列 Jquery 筛选      更新时间:2023-11-25

我正试图使用Jquery为HTML表构建一个选择过滤器,并且我只想过滤该表的第一列,到目前为止我已经得到了这个函数:

$('#select').change(function() {
    var rows = $("#tablebody_hosts").find("tr").hide();
    var data = this.value.split(" ");
    $.each(data, function(i, v) {
        rows.filter(":contains(" + v + ")").show();
    })
});

我如何才能让它只搜索表的第一列中的数据?

试试这个:

rows.filter(function () {
    return $(this).children(':eq(0)').text().indexOf(v) !== -1;
}).show();

代替:

rows.filter(":contains(" + v + ")").show();

文件:http://api.jquery.com/eq-selector/.

您不需要遍历行,只需尝试一下,

rows.filter(function(){
    return (data.indexOf($.trim($(this).children('td').first().text())) != -1);
}).show();

rows.filter(function(){
    return $.inArray($.trim($(this).children('td').first().text()),data);
}).show();
$.each(data, function(i, v) {
  rows.filter(function(){
    return (data.indexOf($.trim($(this).children('td').first().text())) != -1);
 }).show();
 });