无法弄清楚为什么bootstrap导航栏折叠切换不起作用

时间:2015-12-02 06:21:11

标签: twitter-bootstrap-3

我将bootstrap导航栏复制并粘贴到codepen中,但我无法使任何下拉导航栏工作。我正在尝试创建一个网页,在移动设备上查看时,您可以使用下拉按钮进行导航,但我没有运气。这是codepen:http://codepen.io/michaelaharvey/pen/xZKgOX?editors=100 谢谢!!!

    <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="#">Link <span class="sr-only">(current)</span></a></li>
    <li><a href="#">Link</a></li>
    <li class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
      <ul class="dropdown-menu">
        <li><a href="#">Action</a></li>
        <li><a href="#">Another action</a></li>
        <li><a href="#">Something else here</a></li>
        <li role="separator" class="divider"></li>
        <li><a href="#">Separated link</a></li>
        <li role="separator" class="divider"></li>
        <li><a href="#">One more separated link</a></li>
      </ul>
    </li>
  </ul>
  <form class="navbar-form navbar-left" role="search">
    <div class="form-group">
      <input type="text" class="form-control" placeholder="Search">
    </div>
    <button type="submit" class="btn btn-default">Submit</button>
  </form>
  <ul class="nav navbar-nav navbar-right">
    <li><a href="#">Link</a></li>
    <li class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
      <ul class="dropdown-menu">
        <li><a href="#">Action</a></li>
        <li><a href="#">Another action</a></li>
        <li><a href="#">Something else here</a></li>
        <li role="separator" class="divider"></li>
        <li><a href="#">Separated link</a></li>
      </ul>
    </li>
  </ul>
</div><!-- /.navbar-collapse -->

2 个答案:

答案 0 :(得分:1)

问题是因为你没有在Codepen中包含bootstrap.js。你的代码工作得很好..

http://www.codeply.com/go/uZa8lR5x9w

答案 1 :(得分:0)

在codepen设置中,在jquery下添加另一个资源,然后粘贴它:https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js