Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 筛选表Jquery的第一列_Javascript_Jquery_Html_Filter - Fatal编程技术网

Javascript 筛选表Jquery的第一列

Javascript 筛选表Jquery的第一列,javascript,jquery,html,filter,Javascript,Jquery,Html,Filter,我正在尝试使用Jquery为HTML表构建一个select筛选器,我只想筛选该表的第一列,到目前为止,我已经获得了以下函数: $('#select').change(function() { var rows = $("#tablebody_hosts").find("tr").hide(); var data = this.value.split(" "); $.each(data, function(i, v) { rows.filter(":cont

我正在尝试使用Jquery为HTML表构建一个select筛选器,我只想筛选该表的第一列,到目前为止,我已经获得了以下函数:

$('#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();
    })
});

我怎样才能让它只搜索表的第一列中的数据呢?

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

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


您不需要遍历这些行,只要试试这个

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

试试这个:

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

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

试试这个:

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

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

医生:当然可以。您显示的是单元格而不是行,而且,如果给定元素不存在,
indexOf
返回-1。@wared感谢您指出错误,我是否仍缺少任何内容。?当然。您显示的是单元格而不是行,而且,
indexOf
如果给定元素不存在,则返回-1。@wared感谢您指出错误,我是否仍然缺少任何内容。?感谢您的回答,我只是想知道如何精确匹配v的值。例如,如果v为3,则将包括13或23。无论如何,要精确匹配3?@PedroOliveira,我显然被
:contains()
选择器误导了。此解决方案是否符合您的要求(严格相等):
$.trim($(this).children(':eq(0)).text()===v
?@PedroOliveira De nada。感谢您的回答,我只是想知道如何精确匹配v的值。例如,如果v为3,则将包括13或23。无论如何,要精确匹配3?@PedroOliveira,我显然被
:contains()
选择器误导了。此解决方案是否符合您的要求(严格相等):
$.trim($(this).children(':eq(0)').text())==v
?@PedroOliveira De nada。