【问题标题】:jQuery table row filter - hide and show at the same timejQuery表格行过滤器 - 同时隐藏和显示
【发布时间】:2023-03-17 19:40:01
【问题描述】:

我有一个表,其中包含一个包含关键字的列和一个包含与这些关键字对应的选项和值的选择字段(css 类 .filter)。

在我将选择字段更改为另一个选项之前,它工作正常。使用下面的代码,一切都被明显地隐藏了。但是在隐藏之前为每一行添加一个 .show() 不起作用(不再隐藏任何东西)。隐藏后显示选定的行也不行。

$(".filter").change(function () {
        if ($(this).val() != "all") {
            $("tbody").find("tr:not(:contains('"+$(this).val()+"'))").hide(); //hide everything except what contains the selected option

        } else {
            $("tbody").find("tr:hidden").show(); // reset the filter and show everything
        }
    });

【问题讨论】:

    标签: jquery hide show


    【解决方案1】:

    您可以隐藏所有行,然后只显示过滤后的项目

    $("tbody").find("tr").hide().filter(":contains('" + $(this).val() + "')").show();
    

    【讨论】:

    • 嗨,谢谢,这看起来很整洁,对我来说很有意义,但由于某种未知的原因它不起作用。
    • 您好,再次感谢 - 我发现了错误。您的生产线运行良好。比我的优雅。错误是:我有两个具有该类名的元素...愚蠢的我。
    猜你喜欢
    • 2017-01-05
    • 1970-01-01
    • 1970-01-01
    • 2015-10-03
    • 1970-01-01
    • 1970-01-01
    • 2016-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多