gpt4 book ai didi

javascript - jQuery,根据数组检查类

转载 作者:行者123 更新时间:2023-11-27 23:54:05 26 4
gpt4 key购买 nike

这个问题的标题可能会产生误导,但我想不出更好的措辞方式。

让我进入正题吧。我正在使用按钮来过滤状态表。如果我有按钮 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");
});
});

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

最佳答案

目前,您可以隐藏 aSelected 中每个项目的所有其他元素,而不仅仅是在开头。如果您首先隐藏所有内容,然后显示您想要的元素,它应该可以工作:

//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");
});

关于javascript - jQuery,根据数组检查类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32416152/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com