单击后,Bootstrap 3折叠菜单

时间:2014-07-16 16:00:08

标签: javascript jquery menu twitter-bootstrap-3 collapse

我在Bootstrap菜单上遇到了一些问题。 我想在点击其中一个部分后折叠菜单。

HTML:

<div class="container" id="home">
        <nav class="navbar navbar-default navbar-fixed-top" role="navigation">
            <div class="container-fluid">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                        <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</a>
                </div>

                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                        <li class="active"><a href="#home">HOME</a></li>
                        <li><a href="#philosofy">PHILOSOFY</a></li>
                        <li><a href="#knowledge">KNOWLEDGE</a></li>
                        <li><a href="#experience">EXPERIENCE</a></li>
                        <li><a href="#interests">INTERESTS</a></li>
                    </ul>
                </div><!-- /.navbar-collapse -->
            </div><!-- /.container-fluid -->
        </nav>
</div>

我创造了这个小提琴:

http://jsfiddle.net/kHhgw/

1 个答案:

答案 0 :(得分:3)

除菜单按钮外,您还可以使用链接元素中的data-toggle="collapse"data-target="#bs-example-navbar-collapse-1"属性。

所以从你的例子:

<a data-toggle="collapse" data-target="bs-example-navbar-collapse-1" href="#philosofy">PHILOSOFY</a>

更新了小提琴:http://jsfiddle.net/kHhgw/1/