Bootstrap可折叠导航无法正常工作

时间:2015-05-21 23:55:56

标签: javascript jquery twitter-bootstrap collapsable

可崩溃的部分不会工作。 (这部分)

http://imgur.com/PWpHE1G

以下是代码:

<nav class="navbar navbar-inverse navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
          data-target="#navbar" aria-expanded="false" aria-controls="navbar">
        <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="#">Connor Clarke</a>
    </div>
    <div id="navbar" class="collapse navbar-collapse">
      <ul class="nav navbar-nav">
        <li><a href="../index.html">Home</a></li>
        <li class="active"><a href="#">Games</a></li>
        <li><a href="#contact">About</a></li>
      </ul>
    </div><!--/.nav-collapse -->
  </div>
</nav>

1 个答案:

答案 0 :(得分:3)

您提供的代码运行正常,因此您看到的错误必须与页面上的其他代码有关。最有可能的原因是

  1. 您缺少对Bootstrap JavaScript或CSS文件的引用。
  2. 你缺少jQuery。
  3. 您尚未在 Bootstrap JavaScript参考之前放置jQuery
  4. 页面上还有另一个JavaScript错误,请在浏览器控制台中查找错误。
  5. 您的代码工作示例:

    &#13;
    &#13;
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    
    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <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="#">Connor Clarke</a>
        </div>
        <div id="navbar" class="collapse navbar-collapse">
          <ul class="nav navbar-nav">
            <li><a href="../index.html">Home</a></li>
            <li class="active"><a href="#">Games</a></li>
            <li><a href="#contact">About</a></li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </nav>
    &#13;
    &#13;
    &#13;