简体   繁体   English

Bootstrap菜单切换不适用于多个切换链接

[英]Bootstrap menu toggle not working with multiple toggle links

I have a functional side navigation that toggles in and out of display. 我有一个功能性的侧面导航,可以切换显示和不显示。 Here is the "Filter" button... 这是“过滤器”按钮...

<a href="#menu-toggle" style="background-color:black; color:white;" class="btn btn-default page-header" id="menu-toggle">
   <span style="position:relative; top:2px; right: 5px;"class="glyphicon glyphicon-resize-horizontal"></span>
                        Filter</a>

and the JQuery... 和JQuery ...

<script>
    $("#menu-toggle").click(function(e) {
        e.preventDefault();
        $("#wrapper").toggleClass("toggled");
    });
</script>

When I add another clickeable link to toggle the same menu it breaks down but I can't understand why? 当我添加另一个clickeable链接来切换同一菜单时,它会崩溃,但我不明白为什么? I've changed the menu-toggle id to a class but that didn't help. 我已经将菜单切换ID更改为一个类,但这没有帮助。

Here is the code that doesn't work ie the second clickable link that should give the same toggle effect... 这是无效的代码,即第二个可点击链接应具有相同的切换效果...

<li class="sidebar-brand">
     <a href="#" id="menu-toggle">Collapse
     </a>
</li> 

Add a class instead of an ID for multiple elements being operated on. 为要操作的多个元素添加一个类而不是一个ID。

$(".menu-toggle").click(function(e) {
    e.preventDefault();
    $("#wrapper").toggleClass("toggled");
});

Change <a id="menu-toggle"></a> to <a class="menu-toggle"></a> <a id="menu-toggle"></a>更改为<a class="menu-toggle"></a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM