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

jquery简单实现tab选项卡效果

2017-11-06 18:29 816 查看
css:

<style>

div{margin:0;padding:0;width:184px;height:200px;border:1px solid #ccc;display:none;}

.tab{margin:0;padding:0;list-style:none;width:200px;overflow:hidden;}

.tab li{float:left;width:60px;height:30px;background:#ccc;color:#fff;border:1px solid red; text-align:center;line-height:30px;cursor:pointer; }

.on{display:block;}

.tab li.cur{background:blue;}

</style>

html:

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Title</title>

</head>

<body>

<ul class="tab">

<li>最新</li>

<li class="cur">热门</li>

<li>新闻</li>

</ul>

<div>11</div>

<div class="on">22</div>

<div>33</div>

</body>

</html>

js

<script src="js/jquery-3.2.1.js" type="application/javascript"></script>

<script>

$(document).ready(function(){

$(".tab li").click(function(){

$(".tab li").eq($(this).index()).addClass("cur").siblings().removeClass('cur');

$("div").hide().eq($(this).index()).show();

});

});

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