jQuery菜单切换

jQuery菜单切换

点击‘菜单一’,显示‘内容一’

点击‘菜单二’,显示‘内容二’

点击‘菜单三’,显示‘内容三’

 

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>tab</title>
 6 
 7     <style>
 8         *{
 9             margin: 0;
10             padding: 0;
11         }
12         .tab_outer{
13             margin: 20px auto;
14             width: 60%;
15         }
16         .menu{
17             background-color: #cccccc;
18             /*border: 1px solid red;*/
19             line-height: 40px;
20             text-align: center;
21         }
22         .menu li{
23             display: inline-block;
24             margin-left: 14px;
25             padding:5px 20px;
26 
27         }
28         .menu a{
29             border-right: 1px solid red;
30             padding: 11px;
31         }
32         .content{
33             background-color: tan;
34             border: 1px solid green;
35             height: 300px;
36 
37         }
38         .hide{
39             display: none;
40         }
41 
42         .current{
43             background-color: #2868c8;
44             color: white;
45             border-top: solid 2px rebeccapurple;
46         }
47     </style>
48 </head>
49 <body>
50       <div class="tab_outer">
51           <ul class="menu">
52               <li egon="c1" class="current">菜单一</li>
53               <li egon="c2" >菜单二</li>
54               <li egon="c3">菜单三</li>
55           </ul>
56           <div class="content">
57               <div id="c1">内容一</div>
58               <div id="c2" class="hide">内容二</div>
59               <div id="c3" class="hide">内容三</div>
60           </div>
61 
62       </div>
63 </body>
64 
65 
66 <script src="jquery-3.1.1.js"></script>
67     <script>
68          $(".menu li").click(function () {
69 
70              $(this).addClass("current").siblings().removeClass("current")
71 
72              var index=$(this).attr("egon");
73 
74              $("#"+index).removeClass("hide").siblings().addClass("hide")
75 
76          })
77 
78     </script>
79 </html>
View Code

 

转载于:https://www.cnblogs.com/litzhiai/p/8540755.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值