jQuery选项卡的实现(代码简短的)
2013-04-01 19:21
302 查看
<html>
<head>
<meta charset="utf-8"/>
<style>
*{margin:0;padding:0}
body{font-size:15px}
.tab{margin:50px auto;width:300px}
li{list-style:none;height:30px;width:50px;border:1px solid #f50;float:left;margin-left:10px;background:#ccc;border-bottom:none}
.tab_content{clear:both;border:1px solid #000;margin-left:10px;padding:10px;height:200px}
.sport{display:none}
.thing{display:none}
.tab_selected{background:#5FFFFF}
.hover{background:#9f0}
</style>
<script type="text/javascript" src="./script/jquery-1.4.2.min.js"></script>
<script>
$(function(){
var $li=$("div.tab_menu ul li");
$li.click(function(){
var $index=$li.index(this);
$("div.tab_content div").eq($index).show().siblings().hide();
$(this).addClass("tab_selected").siblings().removeClass("tab_selected");
}).hover(function(){
$(this).addClass("hover");
},function(){
$(this).removeClass("hover");
});
});
</script>
</head>
<body>
<div class="tab">
<div class="tab_menu">
<ul>
<li class="tab_selected">时事</li>
<li>体育</li>
<li>娱乐</li>
</ul>
</div>
<div class="tab_content">
<div>时事</div>
<div class="hide">体育</div>
<div class="hide">娱乐</div>
</div>
</div>
</body>
</html>
<head>
<meta charset="utf-8"/>
<style>
*{margin:0;padding:0}
body{font-size:15px}
.tab{margin:50px auto;width:300px}
li{list-style:none;height:30px;width:50px;border:1px solid #f50;float:left;margin-left:10px;background:#ccc;border-bottom:none}
.tab_content{clear:both;border:1px solid #000;margin-left:10px;padding:10px;height:200px}
.sport{display:none}
.thing{display:none}
.tab_selected{background:#5FFFFF}
.hover{background:#9f0}
</style>
<script type="text/javascript" src="./script/jquery-1.4.2.min.js"></script>
<script>
$(function(){
var $li=$("div.tab_menu ul li");
$li.click(function(){
var $index=$li.index(this);
$("div.tab_content div").eq($index).show().siblings().hide();
$(this).addClass("tab_selected").siblings().removeClass("tab_selected");
}).hover(function(){
$(this).addClass("hover");
},function(){
$(this).removeClass("hover");
});
});
</script>
</head>
<body>
<div class="tab">
<div class="tab_menu">
<ul>
<li class="tab_selected">时事</li>
<li>体育</li>
<li>娱乐</li>
</ul>
</div>
<div class="tab_content">
<div>时事</div>
<div class="hide">体育</div>
<div class="hide">娱乐</div>
</div>
</div>
</body>
</html>
相关文章推荐
- jquery 简短几句代码实现给元素动态添加及获取提示信息
- jquery依然简短几句代码实现给元素动态添加及获取提示信息
- 简短几句jquery代码的实现一个图片向上滚动切换
- jquery实现超简洁的TAB选项卡效果代码
- jQuery多项选项卡的实现思路附样式及代码
- jquery代码实现通用选项卡特效功能
- jQuery实现滚动切换的tab选项卡效果代码
- jquery实现经典的淡入淡出选项卡效果代码
- jQuery多项选项卡的实现思路附样式及代码
- jquery实现超简洁的TAB选项卡效果代码
- jQuery实现的多滑动门,多选项卡效果代码
- 基于jQuery实现的仿百度首页滑动选项卡效果代码
- jQuery实现仿腾讯迷你首页选项卡效果代码
- jquery实现经典的淡入淡出选项卡效果代码
- jquery简单实现带渐显效果的选项卡菜单代码
- jquery 简短几句代码实现给元素动态添加及获取提示信息
- 节省代码,利用jquery实现选项卡
- 基于jQuery实现的仿百度首页滑动选项卡效果代码
- jQuery实现仿腾讯迷你首页选项卡效果代码