jquery实现tab切换

参考代码如下:

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Tab切换</title>
<script src="js/jquery-1.7.2.min.js"></script>
</head>
<body>
<div class="container">

<ul class="tabs">
<li class="active"><a href="#tab1">导航菜单</a></li>
<li><a href="#tab4">TAB标签</a></li>
</ul>
<div class="tab_container">
<div id="tab1" class="tab_content" style="display: block; ">

<h3><a href="http://www.freejs.net/article_daohangcaidan_13.html">jquery css多级下拉菜单</a></h3>
<p id="">多级菜单,理论上支持无限多的层级,文件结构非常简单的,具体的请看下面的内容</p>
</div>

<div id="tab4" class="tab_content" style="display: none; ">
<h2>各种tab标签选项卡</h2>
<h3><a href="http://www.freejs.net/article_tabbiaoqian_17.html">tab标签页面,ajax载入</a></h3>

<p> tab标签,jquery ajax载入数据库的内容</p>
</div>
</div>

</div>
<!-- tab切换 -->
<script type="text/javascript">
$(document).ready(function() {

//Default Action
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content

//On Click Event
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active content
return false;
});

});
</script>
</body>
</html>

注:
原文地址:http://www.freejs.net/article_tabbiaoqian_29.html
posted @ 2016-08-02 10:46  hxiuping  阅读(183)  评论(0编辑  收藏  举报