php选项卡思路,两种jQuery实现选项卡功能的方法

实现选项卡有很多方法,但是万变不离其宗,思路很重要,本文主要介绍了jQuery两种方法写选项卡的实例,具有很好的参考价值。下面跟着小编一起来看下吧,希望能帮助到大家。

效果图:

3c215fce6d5fa75e9ccc5349eaf2a363-0.png

代码如下:

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();

})

})

相关推荐:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值