Bootstrap汉堡包菜单无法打开,

时间:2016-02-20 05:12:42

标签: jquery html css twitter-bootstrap

我看过Bootstrap的汉堡包菜单上的所有内容,但没有一个答案对我有用。我想我可能有语法错误,但控制台并没有说有任何错误,我知道我的jQuery和JavaScript是正确链接的。请看一下,让我知道我应该改变什么,这是我的代码:

<nav class="navbar-inverse navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header"><a href="index.html">Google Fiber to Louisville</a>
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="index-header">
        <span class="sr-only">Toggle Navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <div class="collapse navbar-collapse" id="index-header">
      <ul class="nav navbar-left">
        <li id="form-tab"class="nav navbar-right"><a href="#">Add your name!</a></li>
        <li id="supporters-tab"class="navbar-right"><a href="#">Supporters</a></li>
      </ul>
    </div>
  </div>
</nav>

2 个答案:

答案 0 :(得分:1)

您错过了#以标识data-target="index-header"上的ID,应为data-target="#index-header"请参阅Docs

另外(以防万一)确保您拥有所有依赖项:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

jQuery后跟BootstrapJS参见Bootstrap

工作示例代码段。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#index-header" aria-expanded="false">
        <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="index.html">Google Fiber to Louisville</a>
    </div>
    <div class="collapse navbar-collapse" id="index-header">
      <ul class="nav navbar-nav navbar-left">
        <li id="form-tab" class="nav navbar-right"><a href="#">Add your name!</a>
        </li>
        <li id="supporters-tab" class="navbar-right"><a href="#">Supporters</a>
        </li>
      </ul>
    </div>
  </div>
</nav>

答案 1 :(得分:0)

请用

更新你的按钮html
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#index-header">
   <span class="sr-only">Toggle Navigation</span>
   <span class="icon-bar"></span>
   <span class="icon-bar"></span>
   <span class="icon-bar"></span>
</button>

您遗失/不合适class="collapsed"data-target="#index-header"