以编程方式切换bootstrap 3导航栏 [英] Programmatically toggle bootstrap 3 navigation bar

查看:57
本文介绍了以编程方式切换bootstrap 3导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在bootstrap 3导航栏中使用了一些项目,如下所示:

I am using few items in my bootstrap 3 navigation bar grouped in like below:

<nav class="navbar navbar-inverse navbar-fixed-top" id="toggleNav" role="navigation">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">Brand name</a>
        </div>
        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse navbar-ex1-collapse">                
            <ul class="nav navbar-nav navbar-right">
                <li>
                    <a href="javascript:logout();"><span class="glyphicon glyphicon-log-out"></span>&nbsp;Logout</a>
                </li>
                <li>
                    <a href="#" id="online-offline" toggle="offline"><span class="glyphicon glyphicon-off"></span>&nbsp;Go offline</a>
                </li>
            </ul>                
        </div><!-- /.navbar-collapse -->
    </nav> 

当我单击第二项(脱机")时,我使用jquery调用模式窗口.在移动设备上,我必须首先折叠菜单以访问链接,然后单击该项目时,将正确获得模态窗口.

When I click on the second item ('Go offline') I use jquery to invoke a modal window. On mobile I have to first collapse the menu to reach the link, and then when I click on that item I get my modal window correctly.

我需要实现的是在显示模式之前隐藏导航栏折叠.是否可以通过编程方式切换导航栏折叠?我该怎么办?

What I need to achieve is to hide the navbar collapse before showing the modal. Is it possible to programmatically toggle the navbar collapse? How can I do that ?

推荐答案

在@ Jahnux73的帮助下,我自己弄清楚了.因此,我唯一要做的就是添加:

After a little bit of help from @Jahnux73 I figured it out myself. So the only thing I had to do is to add :

data-toggle="collapse" data-target=".navbar-ex1-collapse"

到我想要切换导航栏的特定链接.因此该链接现在如下所示:

to the specific link that I wanted to toggle the navbar. so the link now looks like following:

<a href="#" id="online-offline" data-toggle="collapse" 
   data-target=".navbar-ex1-collapse" toggle="offline">
    <span class="glyphicon glyphicon-off"></span>&nbsp;Go offline
</a>

这篇关于以编程方式切换bootstrap 3导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆