简单教程
提交运行
代码编辑器:
<!DOCTYPE htm> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.js"></script> <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <style>body {margin:20px}</style> <hr> <p class="active-tab"><strong>激活的标签页</strong>:<span></span></p> <p class="previous-tab"><strong>前一个激活的标签页</strong>:<span></span></p> <hr> <ul id="myTab" class="nav nav-tabs"> <li class="active"><a href="#home" data-toggle="tab"> 简单教程</a> </li> <li><a href="#ios" data-toggle="tab">人生</a></li> <li class="dropdown"> <a href="#" id="myTabDrop1" class="dropdown-toggle" data-toggle="dropdown"><b class="caret"></b> </a> <ul class="dropdown-menu" role="menu" aria-labelledby="myTabDrop1"> <li><a href="#jmeter" tabindex="-1" data-toggle="tab"> 畏惧</a> </li> <li><a href="#ejb" tabindex="-1" data-toggle="tab">喜欢</a> </li> </ul> </li> </ul> <div id="myTabContent" class="tab-content"> <div class="tab-pane fade in active" id="home"> <p>总是从自己熟悉的东西中持续获得乐趣,而畏惧不熟悉的东西</p> </div> <div class="tab-pane fade" id="ios"> <p>总是从自己熟悉的东西中持续获得乐趣,而畏惧不熟悉的东西</p> </div> <div class="tab-pane fade" id="jmeter"> <p>总是从自己熟悉的东西中持续获得乐趣,而畏惧不熟悉的东西</p> </div> <div class="tab-pane fade" id="ejb"> <p>总是从自己熟悉的东西中持续获得乐趣,而畏惧不熟悉的东西</p> </div> </div> <script> $(function(){ $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { // 获取已激活的标签页的名称 var activeTab = $(e.target).text(); // 获取前一个激活的标签页的名称 var previousTab = $(e.relatedTarget).text(); $(".active-tab span").html(activeTab); $(".previous-tab span").html(previousTab); }); }); </script>
运行结果: