<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>菜鸟如何学习建站——jquery如何制作tab简单切换篇</title>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(function(){
var li = $("li");
var div = $(".content div");
li.click(function(){
var _this = $(this);
var _index = _this.index();
div.eq(_index).show().siblings("div").hide();
})
})
</script>
<style>
*{
margin:0;
padding:0;
border:0;
}
.content{
margin:50px;
width:400px;
}
.content ul{
overflow:hidden;
_line-height:1px;
}
.content ul li{
list-style:none;
float:left;
padding:0 20px;
border:1px solid #ccc;
margin-left:1px;
}
.hide{
display:none;
}
.tab{
width:400px;
height:200px;
border:1px solid #ccc;
}
</style>
</head>
<body>
<div class="content">
<ul>
<li>菜单一</li>
<li>菜单二</li>
<li>菜单三</li>
</ul>
<div class="tab">内容一</div>
<div class="tab hide">内容二</div>
<div class="tab hide">内容三</div>
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>菜鸟如何学习建站——jquery如何制作tab简单切换篇</title>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(function(){
var li = $("li");
var div = $(".content div");
li.click(function(){
var _this = $(this);
var _index = _this.index();
div.eq(_index).show().siblings("div").hide();
})
})
</script>
<style>
*{
margin:0;
padding:0;
border:0;
}
.content{
margin:50px;
width:400px;
}
.content ul{
overflow:hidden;
_line-height:1px;
}
.content ul li{
list-style:none;
float:left;
padding:0 20px;
border:1px solid #ccc;
margin-left:1px;
}
.hide{
display:none;
}
.tab{
width:400px;
height:200px;
border:1px solid #ccc;
}
</style>
</head>
<body>
<div class="content">
<ul>
<li>菜单一</li>
<li>菜单二</li>
<li>菜单三</li>
</ul>
<div class="tab">内容一</div>
<div class="tab hide">内容二</div>
<div class="tab hide">内容三</div>
</div>
</body>
</html>