2013-04-24 88 views
0

我試圖實現類似的例子,但與拆分按鈕下拉列表導航菜單:引導標籤與拆分按鈕的下拉列表中

「標籤與下拉菜單」 http://twitter.github.io/bootstrap/components.html#navs

http://twitter.github.io/bootstrap/components.html#navbar

我可以有一個拆分按鈕,或者我可以有一個下拉選項卡,但我似乎無法結合這兩者。這可能嗎?

標籤與下拉菜單:

<div class=""> 
    <ul class="nav nav-tabs"> 
     <li class="active"><a href="#">Home</a></li> 
     <li class="dropdown"> 
      <a class="dropdown-toggle" data-toggle="dropdown" href="#">Tab2 <b class="caret"></b></a> 
      <ul class="dropdown-menu"> 
       <li><a href="#">Action</a></li> 
       <li><a href="#">Another action</a></li> 
       <li><a href="#">Something else here</a></li> 
       <li class="divider"></li> 
       <li><a href="#">Separated link</a></li> 
      </ul> 
     </li> 
     <li class="dropdown"> 
      <a class="dropdown-toggle" data-toggle="dropdown" href="#">Tab3<b class="caret"></b></a> 
      <ul class="dropdown-menu"> 
       <li><a href="#">Action</a></li> 
       <li><a href="#">Another action</a></li> 
       <li><a href="#">Something else here</a></li> 
       <li class="divider"></li> 
       <li><a href="#">Separated link</a></li> 
      </ul> 
     </li> 
    </ul> 
</div> 

拆分按鈕:

<div class="btn-toolbar" style="margin: 0;"> 
      <div class="btn-group"> 
      <button class="btn dropdown-toggle" data-toggle="dropdown">Action <span class="caret"></span></button> 
      <ul class="dropdown-menu"> 
       <li><a href="#">Action</a></li> 
       <li><a href="#">Another action</a></li> 
       <li><a href="#">Something else here</a></li> 
       <li class="divider"></li> 
       <li><a href="#">Separated link</a></li> 
      </ul> 
      </div> 
</div> 

回答

0

因此,最終的結果應該是一個拆分按鈕,而不是一個下拉列表中,是否正確?你試過這個嗎? (沒測試過)

<div> 
     <ul class="nav nav-tabs"> 
      <li class="active"> 
       <button class="btn dropdown-toggle" data-toggle="dropdown">Home<span class="caret"></span></button> 
       <ul class="dropdown-menu"> 
        <li><a href="#">Action</a></li> 
        <li><a href="#">Another action</a></li> 
        <li><a href="#">Something else here</a></li> 
        <li class="divider"></li> 
        <li><a href="#">Separated link</a></li> 
       </ul> 
      </li> 
     </ul> 
    </div> 
+0

是(但我把一個div「 btn-group「類的按鈕和UL)。有兩個問題:按鈕沒有顯示爲分離按鈕(只有一個按鈕),我需要爲按鈕設置「data-toggle = tab」,爲下拉菜單設置「data-toggle = dropdown」。 – SturmUndDrang 2013-04-24 12:01:30

0

我已經接近足夠了 - 只需要改變一下樣式。

這裏的HTML:

<!DOCTYPE html> 
    <html lang="en"> 
    <head> 
<meta charset="utf-8"> 
<title>Test Bootstrap</title> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<meta name="description" content=""> 
<meta name="author" content=""> 
<!-- Le styles --> 
<link href="content/bootstrap/css/bootstrap.css" rel="stylesheet"> 
<link href="content/bootstrap/css/bootstrap-responsive.css" rel="stylesheet"> 
</head> 
<body> 
<div class="navbar navbar-static-top"> 
    <div class="navbar-inner"> 
     <div class="container tabbable"> 
      <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> 
       <span class="icon-bar"></span> 
       <span class="icon-bar"></span> 
       <span class="icon-bar"></span> 
      </button> 
      <a class="brand" href="#">ProjectName</a> 
      <div class="nav-collapse collapse"> 
       <ul class="nav"> 
        <li class="active tabbable"><a href="#tab1" data-toggle="tab">tab1</a></li> 
        <li class="tabbable"><a href="#tab2" data-toggle="tab">tab2</a></li> 
        <li class="tabbable" id="tabarea3"> 
         <!--<div class="btn-group" data-toggle="buttons-radio">--> 
         <div class="btn-group"> 
          <a class="btn" id="tab3" href="#tab3" data-toggle="tab">Tab3</a> 
          <button id="tab3button" class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button> 
          <ul class="dropdown-menu"> 
           <li><a href="#">Action</a></li> 
           <li><a href="#">Another action</a></li> 
           <li><a href="#">Something else here</a></li> 
           <li class="divider"></li> 
           <li><a href="#">Separated link</a></li> 
          </ul> 
         </div> 
        </li> 
       </ul> 
      </div> 
     </div> 
    </div> 
</div> 

<!-- Le javascript 
================================================== --> 
<!-- Placed at the end of the document so the pages load faster --> 

<script src="content/bootstrap/js/jquery-1.9.1.js" type="text/javascript"></script> 
<script src="content/bootstrap/js/bootstrap.js" type="text/javascript"></script> 
<script src="content/bootstrap/js/custom.js" type="text/javascript"></script> 

一些jQuery來取消拆分按鈕選項卡(custom.js):

$(document).ready(function() { 
     var $tabs = $('.tabbable li'); 
     $tabs.on('click', function (sender) { 
      if($('#tab3').hasClass('active')) 
      { 
       $('#tab3').removeClass('active'); 
      } 
     }); 
    });