Javascript jQuery,根据数组检查类

Javascript jQuery,根据数组检查类,javascript,jquery,arrays,class,Javascript,Jquery,Arrays,Class,这个问题的标题可能有误导性,但我想不出更好的措辞 让我开门见山。我正在使用按钮筛选状态表。如果我激活了按钮A和按钮B,我只想显示A和B,其余的都是隐藏的。目前我只能让它显示A或B,不能同时显示两者 var aSelected = []; $(".admin_view #filterTable tr td button").on("click", function() { $(this).toggleClass("selected"); //class to show user butto

这个问题的标题可能有误导性,但我想不出更好的措辞

让我开门见山。我正在使用按钮筛选状态表。如果我激活了按钮A和按钮B,我只想显示A和B,其余的都是隐藏的。目前我只能让它显示A或B,不能同时显示两者

var aSelected = [];
$(".admin_view #filterTable tr td button").on("click", function() {
    $(this).toggleClass("selected"); //class to show user button is active
    //Add to array if not in already
    if ($.inArray(this.id,aSelected) == -1) {
        aSelected.push(this.id);
    //Remove from array if button is not active
    } else if ($.inArray(this.id,aSelected) >= 0) {
        aSelected.splice(aSelected.indexOf(this.id), 1);
    }
    //Show all if array is empty
    if (!aSelected.length) {
        $(".admin_view #applicantTable tbody tr").each(function() {
            $(".admin_view #applicantTable tbody tr").removeClass("hidden");
        });
    }
    //This is the section I need help with
    $.map(aSelected, function(a) {
        $(".admin_view #applicantTable tbody tr").not("."+a).addClass("hidden");
        $(".admin_view #applicantTable tbody tr."+a).removeClass("hidden");
    });
});

我需要找到一种方法来比较整个数组,而不是一个数组。

目前,您可以隐藏选定数组中每个项目的所有其他元素,而不仅仅是在开始时。如果您先隐藏所有内容,然后显示所需的元素,则应该可以:

//This is the section I need help with
$(".admin_view #applicantTable tbody tr:not(.hidden)").addClass("hidden");
$.map(aSelected, function(a) {
    $(".admin_view #applicantTable tbody tr.hidden."+a).removeClass("hidden");
});

我觉得这只是我的逻辑问题。这个答案非常有效,谢谢。