最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

两种jQuery实现选项卡功能的方法

来源:动视网 责编:小OO 时间:2020-11-27 15:20:24
文档

两种jQuery实现选项卡功能的方法

效果图。代码如下:<,';';);$(';#p1';).find(';p';).css(';display';,';none';) $(this).attr(';class';,';active';);$(';#p1';).find(';p';).eq($(this).index()).css(';display'。
推荐度:
导读效果图。代码如下:<,';';);$(';#p1';).find(';p';).css(';display';,';none';) $(this).attr(';class';,';active';);$(';#p1';).find(';p';).eq($(this).index()).css(';display'。
 实现选项卡有很多方法,但是万变不离其宗,思路很重要,本文主要介绍了jQuery两种方法写选项卡的实例,具有很好的参考价值。下面跟着小编一起来看下吧,希望能帮助到大家。

效果图:

代码如下:

<!DOCTYPE html>
<html>
 <head>
 <meta charset="UTF-8">
 <script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
 <title>JQuery 源码分析</title>
 <style>
 #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;}
 </style>
 </head>
 <body>
 <p id="p1">
 <input class="active" type="button" value="1" />
 <input type="button" value="2"/>
 <input type="button" value="3"/>
 <p style="display: block;">11111111111</p>
 <p>22222222222</p>
 <p>333333333333</p>
 </p>
 <ul class="tab">
 <li class="active">1</li>
 <li>2</li>
 <li>3</li>
 </ul>
 <ul class="content">
 <li style="display: block;">111111111111</li>
 <li>222222222222</li>
 <li>333333333333</li>
 </ul>
 <script>
 $(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();
 })
 })
 </script>
 </body>
</html>

文档

两种jQuery实现选项卡功能的方法

效果图。代码如下:<,';';);$(';#p1';).find(';p';).css(';display';,';none';) $(this).attr(';class';,';active';);$(';#p1';).find(';p';).eq($(this).index()).css(';display'。
推荐度:
标签: 方法 效果 两种
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top