jqueryJS+DIV+CSS实现选项卡功能 选项卡切换
实现标签切换选项卡显示功能,效果如下:

<html>
<head>
<title>tab</title>
<style>
.tab-title p{color:#666;font-size:15px;font-weight:400; }
.tab-title .selected{color:#356aa0;border-bottom:0px;} /*标题被选中时的样式*/
.tab-title span{padding:5px 9px 5px 10px;border:1px solid #ccc;border-right:0px;margin-left:-1px;cursor:pointer;}
.tab-content .hide{display:none;} /*默认让第一块内容显示,其余隐藏*/
.tab-content ul{padding:5px 10px;overflow:hidden;}
.tab-content ul li{padding-top:5px;}
</style>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.tab-title span').click(function(){
$(this).addClass("selected").siblings().removeClass();//removeClass就是删除当前其他类;只有当前对象有addClass("selected");siblings()意思就是当前对象的同级元素,removeClass就是删除;
var n=$(this).index();
$(".tab-content > ul").hide();
$(".tab-content > ul").eq(n).show();
//$(".tab-content > ul").hide().eq($('.tab-title span').index(this)).show();
});
});
</script>
</head>
<body>
<div class="tab-title">
<p><span class="selected">最新评论</span><span>近期热评</span><span>随机文章</span><span>新闻资讯</span></p>
</div>
<div class="tab-content">
<ul><li>最新评论</li></ul>
<ul class="hide"><li>近期热评</li></ul>
<ul class="hide"><li>随机文章</li></ul>
<ul class="hide"><li>新闻资讯</li></ul>
</div>
<body>
</html>顶(3)
踩(0)
- 最新评论
