jQuery实现点击式选项卡

参考:jQuery权威指南
jQuery初步
jQuery选择器
jQuery操作dom
jQuery操作dom事件
jQuery插件
jQuery操作Ajax
jQuery动画与特效
jQuery实现导航栏
jQuery实现点击式选项卡
jQuery实现select三级联动

效果如下:

211751225971426.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
< html >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=UTF-8" >
< style type = "text/css" >
     body{
         font-size: 13px;
     }
     ul,li{
         margin: 0;padding: 0;
         list-style: none;
     }
     #menu li{
         text-align: center;
         float: left;
         padding: 5px;
         margin-right: 2px;
         width: 50px;
         cursor: pointer;
     }
     #menu li.tabFocus{
         width: 50px;
         font-weight: bold;
         background-color: #f3f2e7;
         border: solid 1px #666;
         border-bottom: 0;
         z-index: 100;
         position: relative;
     }
     #content{
         width: 260px;
         height: 80px;
         padding: 10px;background-color: #f3f2e7;
         clear: left;
         border: solid 1px #666;
         position: relative;
         top: -1px;
     }
     #content li{
         display: none;
     }
     #content li.conFocus{
         display:block;
     }
      
  
</ style >
< script type = "text/javascript" src = "jquery-1.4.4.js" ></ script >
< script type = "text/javascript" >
     $(function(){
         $("#menu li").each(function(index) {//遍历选项卡
             $(this).click(function() {//注册每个选项卡点击事件
                 $("#menu li.tabFocus").removeClass('tabFocus');
                 $(this).addClass('tabFocus');//增加当前选中项样式
                 //显示选项卡对应的内容并影藏不被选中的内容
                 $("#content li:eq("+index+")").show().siblings().hide();
             });
         });
  
  
     });
</ script >
< title >jQuery实现选项卡</ title >
</ head >
< body >
     < ul id = "menu" >
         < li class = "tabFocus" >家居</ li >
         < li >电器</ li >
         < li >二手</ li >
     </ ul >
     < ul id = "content" >
         < li class = "tabFocus" >家居内容</ li >
         < li >电器内容</ li >
         < li >二手内容</ li >
     </ ul >
</ body >
</ html >






转载于:https://www.cnblogs.com/meet/p/4748499.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值