jquery div tab标签切换

实用的div tab标签切换显示代码,可在页面里通用,只不过页面的设计需要遵循下面例子的样式来设计

function changeTab(tabDiv,obj,str,eachDivId,blockTabStyle,noneTabStyle){

$("#"+tabDiv+" a").each(function(c,t){
if(t.id.toLowerCase()== obj.toLowerCase())
$("#"+ obj).attr("className",blockTabStyle);
else
$("#"+ t.id).attr("className",noneTabStyle);
});
var divid= str+obj;
$("#"+ eachDivId +" div").each(function(i,item){
if(divid.toLowerCase() == item.id.toLowerCase()){
$("#"+ obj).show();
}
else{
$("#"+ item.id).hide();
}

});

}



html 测试代码:需要引用JQUERY

<!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="public/js/jquery-1.4.min.js"></script>
<style type="text/css">
.a{ font-size:12px; color:#000}
.b{ font-size:12px; color:#06F; font-weight:bold;}
</style>

</head>

<body>
<div id="layer1"><a href="#" οnclick="changeTab('layer1',this.id,'str','y','b','a')" id="l1">1</a><a href="#" id="l2" οnclick="changeTab('layer1',this.id,'str','y','b','a')">2</a><a href="#" id="l3" οnclick="changeTab('layer1',this.id,'str','y','b','a')">3</a></div>

<div id="y">
<div id="strl1" style="display:none;">a</div>
<div id="strl2" style="display:none;">b</div>
<div id="strl3" style="display:none;">c</div>
</div>
</body>
</html>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值