删除在JavaScript中单击另一个手风琴时显示手风琴
浏览本网站: 我希望输出像, 如果我单击一个侧栏菜单,其他侧栏菜单应该折叠 单击之前:删除在JavaScript中单击另一个手风琴时显示手风琴,javascript,html,css,Javascript,Html,Css,浏览本网站: 我希望输出像, 如果我单击一个侧栏菜单,其他侧栏菜单应该折叠 单击之前: 单击后: 我想这就是代码 $(document).ready(function() { $('.sidebar-link').click(function(e) { e.preventDefault(); var $this = $(this); if ($this.next().hasClass('show')) { $t
单击后:
我想这就是代码
$(document).ready(function() {
$('.sidebar-link').click(function(e) {
e.preventDefault();
var $this = $(this);
if ($this.next().hasClass('show')) {
$this.next().removeClass('show');
$this.next().slideUp(350);
} else {
$this.parent().parent().find('sidebar-submenu-item .sidebar-submenu').removeClass('show');
$this.parent().parent().find('sidebar-submenu-item .sidebar-submenu').slideUp(350);
$this.next().toggleClass('show');
$this.next().slideToggle(350);
}
});
如何修改以获得预期的输出。请帮帮我 试试这个:
$('.sidebar-link').click(function (e) {
e.preventDefault();
$('.show').removeClass("show");
$('.show').css("style","none");
......
});
试试这个:
$(document).ready(function() {
$('.sidebar-link').click(function(e) {
e.preventDefault();
var $this = $(this);
document.querySelectorAll('.sidebar-link').forEach(el=> {
el.classList.remove('show')
});
e.classList.add('show');
$this.parent().parent().find('sidebar-submenu-item .sidebar-submenu').removeClass('show');
$this.parent().parent().find('sidebar-submenu-item .sidebar-submenu').slideUp(350);
$this.next().toggleClass('show');
$this.next().slideToggle(350);
});
兄弟,我试过你的密码。但如果我点击另一个侧边栏菜单,之前打开的菜单并没有关闭。我只是告诉你从所有菜单中删除“show”类的方法。因为你有内联风格。我编辑了我的答案