html部分
<ul class="tab"> <li>最新</li> <li class="cur">热门</li> <li>新闻</li> </ul> <div>11</div> <div class="on">22</div> <div>33</div>
css部分
<style type="text/css"> 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:poi。 nter; } .on{display:block;} .tab li.cur{background:blue;} </style>
jquery部分
<script type="text/javascript"> $(document).ready(function(){ $(".tab li").click(function(){ $(".tab li").eq($(this).index()).addClass("cur").siblings().removeClass(‘cur‘); $("div").eq($(".tab li").index(this)).toggle().siblings("div").hide(); )}; )}; </script>
实现的效果大概就是每次点击一下的时候是正常选项卡,每个选项卡第二次点击的时候会隐藏当前部分;
原文:http://www.cnblogs.com/zhousiyuya/p/6254264.html