2015-10-12 63 views
0

感謝您的時間來看看我的問題。按鈕打開所有並關閉所有的Twitter Bootstrap下拉菜單的onClick

爲了進一步說明,我在下面提供了一些示例代碼。如果您在「發佈」菜單項,點擊第一個,然後關閉所有按鈕,它並沒有關閉所有和我希望它...

<!DOCTYPE html> 
    <html lang="en"> 
    <head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> 
    <title>Bootstrap dropdown</title> 
    <!-- Bootstrap --> 
    <link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet"> 

    <style> 
    body { 
      background: #222222; 
     } 
     .nav-tabs { 
      border-bottom: none; 
      margin-left: 0; 
     } 
     ul.nav .dropdown.open { 
      background: #323433; 
     } 
     ul.nav .dropdown.open button span.caret { 
      -webkit-transform: rotate(90deg); 
      -moz-transform: rotate(90deg); 
      -ms-transform: rotate(90deg); 
      transform: rotate(90deg); 
     } 
     ul.nav .dropdown-menu > li > a:focus, ul.nav .dropdown-menu > li > a:hover { 
      color: #262626; 
      text-decoration: none; 
      background-color: #000000; 
     } 
     ul.nav .dropdown-menu li.active { 
      background: #008265; 
     } 
     ul.nav .dropdown { 
      border-bottom: solid 1px #3f3f3f; 
      position: initial !important; 
      clear: both; 
     } 
     ul.nav .dropdown .btn-default { 
      background-color: transparent; 
      border: none; 
      display: block; 
      padding: 12px 30px 12px 20px; 
      color: white; 
      margin-left: 0; 
      position: relative; 
      width: 100%; 
      text-align: left; 
     } 

     ul.nav .dropdown .btn-default .caret { 
      position: absolute; 
      right: 15px; 
      top: 22px; 
      border-top: 4px solid transparent; 
      border-bottom: 4px solid transparent; 
      border-left: 4px solid white; 
      border-right: none; 
      -moz-transition: 0.5s ease-in-out; 
      -webkit-transition: 0.5s ease-in-out; 
      transition: 0.5s ease-in-out; 
     } 

     ul.nav .dropdown ul.dropdown-menu { 
      position: initial; 
      width: 100%; 
      background: #323433; 
      padding-top: 0px; 
      padding-bottom: 5px; 
      border-top: none; 
      border-right: none; 
      border-radius: 0; 
     } 

     ul.nav .dropdown ul.dropdown-menu li a { 
      padding: 5px 5px 5px 30px; 
      color: white; 
     } 

     ul.nav .dropdown ul.dropdown-menu > .active > a { 
      color: #fff; 
      text-decoration: none; 
      background-color: transparent; 
      outline: 0; 
     } 
     ul.nav .dropdown.open ul.dropdown-menu { 
      display: block !important; 
     } 
    </style> 
    </head> 
    <body> 
    <div class="container"> 
       <ul id="accordion" class="nav nav-tabs"> 
        <div class="dropdown"> 
         <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" 
           aria-expanded="false"> 
          Library 
          <span class="caret"></span> 
         </button> 
         <ul class="dropdown-menu"> 
          <li><a href="#">Carriers</a></li> 
          <li><a href="#">Threats</a></li> 
          <li><a href="#">Mitigations</a></li> 
         </ul> 
        </div> 
        <!-- end of menu--> 
        <div class="dropdown"> 
         <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"> 
          Publication 
          <span class="caret"></span> 
         </button> 
         <ul class="dropdown-menu"> 
          <li><a href="#">Library Threat Changes</a></li> 
          <li><a href="#">Library 
           Mitigation Changes</a></li> 
          <li><a href="#">Published Data</a></li> 
         </ul> 
        </div> 
        <!-- end of menu--> 
        <div class="dropdown"> 
         <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"> 
          Publication 
          <span class="caret"></span> 
         </button> 
         <ul class="dropdown-menu"> 
          <li><a href="#">Library Threat Changes</a></li> 
          <li><a href="#">Library 
           Mitigation Changes</a></li> 
          <li><a href="#">Published Data</a></li> 
         </ul> 
        </div> 
        <!-- end of menu--> 
        <div class="dropdown"> 
         <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"> 
          Publication 
          <span class="caret"></span> 
         </button> 
         <ul class="dropdown-menu"> 
          <li><a href="#">Library Threat Changes</a></li> 
          <li><a href="#">Library 
           Mitigation Changes</a></li> 
          <li><a href="#">Published Data</a></li> 
         </ul> 
        </div> 
        <!-- end of menu--></ul> 
    </div> 
    <div class="container"> 
     <button class="openall" style="display:inline-block;">Expand</button> 
     <button class="closeall" style="display:inline-block;">Collapse</button> 
    </div> 
    </div> 
    <!-- /.container --> 

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> 
    <script src="http://getbootstrap.com/dist/js/bootstrap.min.js"></script> 
    <script> 

$('.openall').click(function(e){ 
     $('#accordion').removeClass('collapseMenu') 
     $('.dropdown').removeClass('open') 
     $('.dropdown').addClass('open'); 
     $('.dropdown button').attr('aria-expanded','true'); 
     e.stopPropagation(); 
    }); 

$('.closeall').click(function(e){ 
     $('.dropdown').removeClass('open') 
     $('.dropdown button').attr('aria-expanded','false'); 
     $('#accordion').removeClass('collapseMenu') 
     e.stopPropagation(); 
    }); 

    // ADD SLIDEDOWN ANIMATION TO DROPDOWN // 
    $('.dropdown').on('show.bs.dropdown', function(e){ 
     $(this).find('.dropdown-menu').first().stop(true, true).slideDown(); 
    }); 

    // ADD SLIDEUP ANIMATION TO DROPDOWN // 
    $('.dropdown').on('hide.bs.dropdown', function(e){ 
     $(this).find('.dropdown-menu').first().stop(true, true).slideUp(); 
    }); 
    </script> 

    </body> 
    </html> 
+1

可能重複[Bootstrap摺疊 - 全部展開](http://stackoverflow.com/questions/22057505/bootstrap-collapse-expand-all) – Jim

+0

@Jim下拉列表不同於手風琴 – Ian

回答

相關問題