1. 程式人生 > >Bootstrap使用Tab和dropdown實現導航下拉選單效果

Bootstrap使用Tab和dropdown實現導航下拉選單效果

<!DOCTYPE html>
<html>
<head>
   <meta charset="utf-8">
    <title>Dropdown</title>
     <!--引用相應的CSS和JQ外掛-->
     <link href="dist/css/bootstrap.css" rel="stylesheet" type="text/css">
     <link href="dist/css/bootstrap.min.css" rel="stylesheet" type="text/css"
>
<link href="dist/css/bootstrap-theme.css" rel="stylesheet" type="text/css"> <link href="dist/css/bootstrap-theme.min.css" rel="stylesheet" type="text/css"> <script type="text/javascript" src="js/tests/vendor/jquery.min.js"></script> <script type="text/javascript"
src="dist/bootstrap.js">
</script> <script type="text/javascript" src="dist/bootstrap.min.js"></script> <script type="text/javascript" src="dist/npm.js"></script> <script type="text/javascript" src="js/tab.js"></script> <script type="text/javascript"
src="js/dropdown.js">
</script> </head> <body> <ul class="nav nav-tabs" id="myTab"> <li><a href="#home" data-toggle="tab">首頁</a></li> <li><a href="#about" data-toggle="tab">關於</a></li> <li><a href="#contact" data-toggle="tab">聯絡</a></li> <li class="dropdown"><a href="#" id="address" class="dropdown-toggle" data-toggle="dropdown" >地址 <b class="caret"></b></a> <ul class="dropdown-menu" role="menu" aria-labelledby="address"> <li ><a href="#addressa" date-toggle="tab" tabindex="-1">地址1</a></li> <li ><a href="#addressb" date-toggle="tab" tabindex="-1" >地址2</a></li> <li ><a href="#addressc" date-toggle="tab" tabindex="-1">地址3</a></li> <li ><a href="#addressd" date-toggle="tab" tabindex="-1">地址4</a></li> </ul> </li> </ul> <div class="tab-content"> <!--預設選擇home active--> <div class="tab-pane active" id="home"> home </div> <div id="about" class="tab-pane"> about </div> <div id="contact" class="tab-pane"> contact </div> <div id="addressa" class="tab-pane"> addressa </div> <div id="addressb" class="tab-pane"> addressb </div> <div id="addressc" class="tab-pane" > addressc </div> <div id="addressd" class="tab-pane" > addressd </div> </div> </body> <script type="text/javascript"> /*下拉選單切換*/ $('.dropdown-toggle').dropdown(); /*啟用選項卡*/ $("#myTab a").click(function(e){ e.preventDefault();/*不要執行與事件有關的預設動作*/ $(this).tab('show'); }); </script> </html>