您的位置:首页 > Web前端 > JQuery

jquery tab选项卡

2014-06-19 09:36 489 查看
<!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=gb2312" />
<title>选项卡效果</title>
<script type="text/javascript" src="js/jquery-1.7b2.js"></script>
<script type="text/javascript">
$(document).ready(function(){ //页面加载时
$('.ct:gt(0)').hide();
var hwd=$('.box ul li');
/*hwd.hover(function(){ //鼠标移上去背景变化,hover事件
$(this).addClass('two')
.siblings().removeClass(); //删除兄弟节点
});*/
hwd.hover(function(){
$(this).addClass('one')//向匹配的元素添加指定的类名。
.siblings().removeClass();
var hwd_index=hwd.index(this);//搜索匹配的元素,并返回相应元素的索引值,从0开始计数。
//alert(hwd_index);
$('.ct').eq(hwd_index).show().siblings().hide();
});

});
</script>
<style>
*{ padding:0px; margin:0px;}
body{ font-size:12px; padding:100px;}
ul{ list-style-type:none;}
.box ul{ height:30px; line-height:30px;}
.box ul li{ float:left; padding:0 10px;cursor:pointer; position:relative; background:url(images/bg1.png) repeat-x; border:1px solid #dbe2e7; margin-right:5px; border-bottom:none;}
.content{ width:325px; border:1px solid #dbe2e7; padding:10px;}
* html.content{ margin-top:-1px;}
.box ul li.one{ background:#fff; }
.box ul li.two{ background:orange;}
</style>

</head>

<body>
<div class="box">
<ul>
<li class="one">菜单一</li>
<li>菜单二</li>
<li>菜单三</li>
</ul>
<div class="content">
<div class="ct">菜单一的内容</div>
<div class="ct">菜单二的内容</div>
<div class="ct">菜单三的内容</div>
</div>
</div>
</body>
</html>
效果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: