作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一些可折叠菜单,我想在单击时隐藏其他菜单。请注意,我想完全隐藏它们,而不是折叠它们。它与 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/
我是一名优秀的程序员,十分优秀!