jQuery实现简单的tab切换
html:
<section>
<nav id="nav">
<a class="on">tab1</a>
<a>tab2</a>
<a>tab3</a>
<a>tab4</a>
</nav>
<div id="contentBox">
<div class="box active">内容一</div>
<div class="box">内容二</div>
<div class="box">内容三</div>
<div class="box">内容四</div>
</div>
</section>
css:
*{box-sizing:border-box;}
#nav{height:50px;}
#nav a{display:block;height:50px;line-height:50px;padding:0 15px;font-size:18px;text-align:center;font-family: 'Microsoft YaHei';float:left;background- color:#e1e1e1;cursor:pointer;}
#nav a.on{border-bottom:2px solid #e60012;}
#contentBox{width:280px;height:100px;}
#contentBox .box{text-align:center;line-height:100px;font-size:24px;font-weight:blod;display:none;}
#contentBox .box.active{display:block;}
js:
//简单jq tab index从0开始
$(function(){
$("#nav a").off("click").on("click",function(){
var index = $(this).index();
$(this).addClass("on").siblings().removeClass("on");
$("#contentBox .box").eq(index).addClass("active").siblings().removeClass("active");
});
});
出处:https://www.cnblogs.com/zmdComeOn/
个性签名:努力生活,努力走路
阿里云拼团:https://www.aliyun.com/1111/home?userCode=f4ee1llo1核2G1M,86一年,229三年;2核4G5M,799三年;2核8G5M,1399三年
腾讯云三月采购计划特价:https://cloud.tencent.com/act/cps/redirect?redirect=1073&cps_key=15d0b1673287c43fe946626d9f4e2eee&from=console1核2G1M,88一年;1核2G1M,268三年;2核4G5M,998一年;4核8G5M,2888元三年