实际项目导航栏菜单切换的简单实现

124925503.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
< html  xmlns = "http://www.w3.org/1999/xhtml" >
< head >
     < meta  http-equiv = "Content-Type"  content = "text/html;charset=UTF-8"  />
     < title >url-test</ title >
     < style  type = "text/css" >
         .nav{
             background-color:pink;
             width:800px;
             height:100px;
             leight:100px;
             margin:0 auto;
         }
         .nav ul{
             list-style-type:none;
             margin:0px;
             padding:0px;
         }
         .nav ul li{
             float:left;
             height:100px;
             line-height:100px;
             width:195px;
             margin-left:4px;
         }
         .nav ul li a{
             text-decoration:none;
             background-color:#c3d9ff;
             display:block;
             text-align:center;
         }
         .nav ul li a:hover{
             font-size:50px;
             color:red;
             background-color:white;
         }
         .nav .current{
             background-color:red;
             color:white;
             font-size:50px;
         }
     </ style >
</ head >
< body >
                           
     < div  class = "nav" >
         < ul  id = "menu" >
             < li >< a  href = "file:///C:/Users/Administrator/Desktop/demo/billing/menu1/html.html"  id = "menu1" >menu1</ a ></ li >
             < li >< a  href = "file:///C:/Users/Administrator/Desktop/demo/billing/menu2/html.html"  id = "menu2" >menu2</ a ></ li >
             < li >< a  href = "file:///C:/Users/Administrator/Desktop/demo/billing/menu3/html.html"  id = "menu3" >menu3</ a ></ li >
             < li >< a  href = "file:///C:/Users/Administrator/Desktop/demo/billing/menu4/html.html"  id = "menu4" >menu4</ a ></ li >
         </ ul >
     </ div >
     < script  type = "text/javascript"  src = "http://lib.sinaapp.com/js/jquery/1.8.1/jquery.min.js" ></ script >
     < script  type = "text/javascript" >
                               
         $(document).ready(function(){
             var currenturl = window.location.href;
             if(currenturl.indexOf("/menu1/") != -1) {
                 $(".nav").find("li").eq(0).find("a").addClass("current");
                 return false;
             } else if(currenturl.indexOf("/menu2/") != -1) {
                 $(".nav").find("li").eq(1).find("a").addClass("current");
                 return false;
             } else if(currenturl.indexOf("/menu3/") != -1 ) {
                 $(".nav").find("li").eq(2).find("a").addClass("current");
                 return false;
             } else if(currenturl.indexOf("/menu4") != -1) {
                 $(".nav").find("li").eq(3).find("a").addClass("current");
                 return false;
            
         });
     </ script >
</ body >
</ html >


demo下载:导航栏菜单切换简单实现Demo




     本文转自韩立伟 51CTO博客,原文链接:http://blog.51cto.com/hanchaohan/1320803,如需转载请自行联系原作者




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值