【问题标题】:filtering table using jquery function and dropdown select使用 jquery 函数和下拉选择过滤表
【发布时间】:2015-02-11 16:01:36
【问题描述】:

我正在尝试根据下拉列表中的选定值显示和隐藏行。用户选择 user_name 后,我可以使用按钮在表中隐藏此用户行,但我想在选择后显示和隐藏行而不单击按钮,我无法让它工作。

这是我使用按钮的工作功能:

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

这是在尝试避免使用按钮后不起作用的功能:

$(document).ready(function() {
    $("selectedName").change(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();
        });
    });
});

我在第二个中做错了什么?

【问题讨论】:

  • 如果您也显示您的 HTML,我们会更容易为您提供帮助
  • 您的意思是$(".selectedName").change() 还是第二个代码sn-p 中的$("#selectedName").change

标签: jquery html


【解决方案1】:

您的选择器在第二个代码块中无效:

$("selectedName") 如果选择的名字是一个类,那么你需要$(".selectedName"),或者如果它是一个id,那么$("#selectedName")

【讨论】:

    猜你喜欢
    • 2021-08-01
    • 2017-09-09
    • 1970-01-01
    • 1970-01-01
    • 2022-12-15
    • 2014-02-05
    • 1970-01-01
    • 2012-03-25
    • 1970-01-01
    相关资源
    最近更新 更多