<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hello World</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"/>
</head>
<body>
<div>
<ul class="nav nav-tabs" id="mytab">
<li role="presentation" ><a href="#tab-1">第一项</a></li>
<li role="presentation"><a href="#tab-2">第二项</a></li>
<li role="presentation"><a href="#tab-3">第三项</a></li>
<li role="presentation"><a href="#tab-4">第四项</a></li>
</ul>
<div>
<div id="tab-1"></div>
<div id="tab-2">慕课网是做什么的</div>
<div id="tab-3"></div>
<div id="tab-4"></div>
</div>
</div>
<script src="/ http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script>
$(document).ready(function(){
$('#mytab a[href="#tab-2"]').tab('show')
});
</script>
</body>
</html>
你的HTML代码写的不对,参考官方给的写法:
http://v3.bootcss.com/javascript/#tabs-examples
<div>
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Home</a></li>
<li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li>
<li role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">Messages</a></li>
<li role="presentation"><a href="#settings" aria-controls="settings" role="tab" data-toggle="tab">Settings</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="home">...</div>
<div role="tabpanel" class="tab-pane" id="profile">...</div>
<div role="tabpanel" class="tab-pane" id="messages">...</div>
<div role="tabpanel" class="tab-pane" id="settings">...</div>
</div>
</div>