实现选项卡有很多方法,但是万变不离其宗,思路很重要,本文主要介绍了jquery两种方法写选项卡的实例,具有很好的参考价值。下面跟着小编一起来看下吧,希望能帮助到大家。
效果图:
代码如下:
nbsp;html>JQuery 源码分析 #p1 p{width: 200px;height: 200px;border: 1px solid #FF0000;display: none;} .active{background: red;} *{margin: 0;padding: 0;} .tab:after{content: '';display: block;clear: both;} .tab li{width: 150px;height: 30px;line-height: 30px;text-align: center;cursor: pointer;list-style: none;float: left;margin: 0 10px;background: #ABCDEF;border-radius: 5px;} .tab li.active{background: #000;color:#fff;} .content:after{content: '';display: block;clear: both;} .content li{width: 460px;height: 300px;padding:20px;background: #f7f7f7;display: none;}
11111111111
22222222222
333333333333
登录后复制 1 2 3 111111111111 222222222222 333333333333 $(function(){ //jQuery 方法一 $('#p1').find('input').click(function(){ $('#p1').find('input').attr('class',''); $('#p1').find('p').css('display','none') $(this).attr('class','active'); $('#p1').find('p').eq($(this).index()).css('display','block'); }); //jQuery 方法二 $('.tab').find('li').click(function(){ var index = $(this).index(); $(this).addClass('active').siblings().removeClass('active'); $('.content').find('li').eq(index).show().siblings().hide(); }) })
相关推荐:
jQuery移动端Tab选项卡效果实现方法
JavaScript插件Tab选项卡详解
jquery实现tab选项卡切换效果
以上就是两种jQuery实现选项卡功能的方法的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2789549.html