gpt4 book ai didi

javascript - Bootstrap 4 : How to show one collapsible item and hide others?

转载 作者:行者123 更新时间:2023-11-28 03:31:36 26 4
gpt4 key购买 nike

我有一些可折叠菜单,我想在单击时隐藏其他菜单。请注意,我想完全隐藏它们,而不是折叠它们。它与 Accordion 行为不同。

我使用了 Accordion 代码并添加了以下功能:

$('#bottomNavBar .collapse').on('show.bs.collapse', function (e) {
// do something…
var me = e.target;
$('#bottomNavBar [aria-expanded="false"]').each(function () {
if (!$(this).is(me)) {
$(this).hide();
}
});
});

问题是,单击展开的项目也被隐藏,因为它的 aria-expanded 为 false(但是它的子菜单出现)。由于我的视觉计划,我不想使用 shown.bs.collapse 事件。我尝试将每个项目与调用对象进行比较,但它仍然不起作用。

最佳答案

这个函数解决了我的问题,我只需要click事件。

$('#bottomNavBar [aria-expanded="false"]').on('click', function (e) {
// do something…
var me = this;
$('#bottomNavBar [aria-expanded="false"]').each(function () {
if (this != me) {
$(this).hide();
}
});
});

关于javascript - Bootstrap 4 : How to show one collapsible item and hide others?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58131071/

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