根据bootstrap下拉项目更改`div`的内容

时间:2016-05-26 12:13:15

标签: javascript jquery html css twitter-bootstrap

我有一个bootstrap导航栏。我有多个下拉项目。

现在我有了另一个div col-md-3

在这个div中,我想显示我悬停的下拉项目。现在,如果我将鼠标悬停在下拉菜单上,则显示子菜单而不是单击。

那么如何在该div中显示drodown菜单的子项呢?

我希望子项目在下拉列表中,并且也在那个侧栏中。

我的代码是这样的:

  <nav class="navbar navbar-default">
   <div class="container-fluid">
      <!-- Brand and toggle get grouped for better mobile display -->
      <div class="navbar-header">
         <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" 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>
      </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><a  href="#">Dashboard</a></li>
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Administration <span class="caret"></span></a>
                <ul class="dropdown-menu">
                  <li><a href="#">Time Zone</a></li>
                  <li><a href="#">Holidays</a></li>
                  <li><a href="#">Working Hours</a></li>
                  <li><a href="#"> Promt Language</a></li>
                  <li><a href="#">Phone No Allocation & Extensions</a></li>
                  <li><a href="#">Speed Dial</a></li>
                  <li><a href="#">Confernce Welcome Message</a></li>
               </ul>
            </li>
            <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dial Plan<span class="caret"></span></a>
               <ul class="dropdown-menu">
                  <li><a href="#">Current Dial Plan</a></li>

                  <li><a href="#">Caller ID Management</a></li>
                  <li><a href="#">ISD Management</a></li>
                  <li><a href="#">Block Number</a></li>
                  <li><a href="#">Override</a></li>
                  <li><a href="#">Location</a></li>
               </ul>

            </li>
            <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Routing<span class="caret"></span></a>
               <ul class="dropdown-menu">
                  <li><a href="#">24 Hours</a></li>
                  <li><a href="#">Working Hours</a></li>
                  <li><a href="#">OFF Hours</a></li>
                  <li><a href="#"> Location Based Routing </a></li>
               </ul>

            </li>
            <li><a href="#">Call Recording</a></li>

            <li class="dropdown">
               <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Users <span class="caret"></span></a>
               <ul class="dropdown-menu">
                  <li><a href="#">Add User</a></li>
                  <li><a href="#">View Users</a></li>
               </ul>
            </li>

            <li class="dropdown">
               <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Voice Mail<span class="caret"></span></a>
               <ul class="dropdown-menu">
                  <li><a href="#">Default</a></li>
                  <li><a href="#">For each user</a></li>
               </ul>
            </li>

            <li class="dropdown">
               <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Provisioning <span class="caret"></span></a>
               <ul class="dropdown-menu">
                  <li><a href="#">Manual Softphone Configuration</a></li>
                  <li><a href="#">Add Deskphone</a></li>
                  <li><a href="#">Devices</a></li>
                  <li><a href="#">Edit</a></li>
                  <li><a href="#">Delete</a></li>

               </ul>
            </li>

         </ul>
      </div>
      <!-- /.navbar-collapse -->
   </div>
   <!-- /.container-fluid -->
</nav>


<div class="container-fluid">
            <div class="col-md-12" >
            <!-- Side bar-->
                <div class="col-md-3">

                </div>

            </div>
</div>

1 个答案:

答案 0 :(得分:0)

您的代码是正确的,但似乎您忘记在代码中包含jQuery。 我使用你的代码创建了一个Codepen,并且在包含Bootstrap库之前我已经在底部包含了jQuery.js。 正如您所看到的,下拉项目工作正常,当您从代码中删除jQuery脚本时,您可以重现已损坏的场景。

以下是链接:Codepen Link

<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>