导航栏中的Bootstraps下拉菜单无法打开

时间:2017-07-28 16:19:29

标签: jquery twitter-bootstrap navbar

我的导航栏中的下拉菜单无法打开(如果我省略打开)或一直保持打开状态(当我在下面的版本中添加打开时)。即使我省略了打开它怎么能打开它怎么能再次关闭呢? (链接到jQ ery和 bootstrapcdn 都有):



<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<body data-spy="scroll" data-target=".navbar">
  <!--navbar starts here-->
  <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <div class="container-fluid">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse"
  data-target=".navbar-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="#">
          <img alt="Brand" src="...">
        </a>

        <div class="projectName"> 
          <a href="#">ДЖУЛИН</a>
        </div>
      </div>

      <div class="navbar-collapse collapse">
        <ul class="nav navbar-nav navbar-right">
          <li class="active"> <a href="#home"> HOME </a> </li>
          <li class="dropdown open" role="presentation">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown"       role="button" aria-haspopup="true" aria-expanded="false"> WORK <span    class="caret"></span>
            </a>
            <ul class="dropdown-menu">
              <li><a href="#work1" class="scroll-nav">Work 1</a></li>
              <li><a href="#work2" class="scroll-nav">Work 2</a></li>
            </ul>
         </li>

         <li class="active"> <a href="#about"> ABOUT </a> </li>
         <li class="active"> <a href="#faq"> FAQ </a> </li>
         <li class="active"> <a href="#contact"> CONTACT </a></li>
      </ul>

    </div> <!--collapse-->
  </div> <!--header-->
 </div> <!-- end nav container -->
</nav> <!-- end navbar-->
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

您可以使用解决方案https://jsfiddle.net/08xp0q92/

&#13;
&#13;
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<body data-spy="scroll" data-target=".navbar">
  <!--navbar starts here-->
  <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <div class="container-fluid">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse"
  data-target=".navbar-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="#">
          <img alt="Brand" src="...">
        </a>

        <div class="projectName"> 
          <a href="#">ДЖУЛИН</a>
        </div>
      </div>

      <div class="navbar-collapse collapse">
        <ul class="nav navbar-nav navbar-right">
          <li class="active"> <a href="#home"> HOME </a> </li>
          <li class="dropdown open" role="presentation">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"> WORK <span    class="caret"></span>
            </a>
            <ul class="dropdown-menu">
              <li><a href="#work1" class="scroll-nav">Work 1</a></li>
              <li><a href="#work2" class="scroll-nav">Work 2</a></li>
            </ul>
         </li>

         <li class="active"> <a href="#about"> ABOUT </a> </li>
         <li class="active"> <a href="#faq"> FAQ </a> </li>
         <li class="active"> <a href="#contact"> CONTACT </a></li>
      </ul>

    </div> <!--collapse-->
  </div> <!--header-->
 </nav> <!-- end nav container -->
</body> <!-- end navbar-->
&#13;
&#13;
&#13;

您必须包含 bootstrap.js