欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

简单的jquery左侧导航栏和页面选中效果

程序员文章站 2022-06-14 12:01:15
这里是要实现导航的左侧并选中的,此功能需引用jquery 左侧导航:

    这里是要实现导航的左侧并选中的,此功能需引用jquery

    左侧导航:

    <p class="box">
    <ul class="menu">
    <li class="level1">
    <a href="#none" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >衬衫</a>
    <ul class="level2">
    <li><a href="#none" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >短袖衬衫</a></li>
    <li><a href="#none" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >长袖衬衫</a></li>
    <li><a href="#none" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >短袖t恤</a></li>
    <li><a href="#none" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >长袖t恤</a></li>
    </ul>
    </li>
    <li class="level1">
    <a href="#none" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >卫衣</a>
    <ul class="level2">
    <li><a href="#none" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >开襟卫衣</a></li>
    <li><a href="#none" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >套头卫衣</a></li>
    <li><a href="#none" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >运动卫衣</a></li>
    <li><a href="#none" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >童装卫衣</a></li>
    </ul>
    </li>
    <li class="level1">
    <a href="#none" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >裤子</a>
    <ul class="level2">
    <li><a href="#none" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >短裤</a></li>
    <li><a href="#none" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >休闲裤</a></li>
    <li><a href="#none" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >牛仔裤</a></li>
    <li><a href="#none" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >免烫卡其裤</a></li>
    </ul>
    </li>
    </ul>
    </p>
    js代码:
    <script type="text/javascript">
    //等待dom元素加载完毕.
    $(document).ready(function(){
    $(".level1 > a").click(function(){
    $(this).addclass("current") //给当前元素添加"current"样式
    .next().show() //下一个元素显示
    .parent().siblings().children("a").removeclass("current") //父元素的兄弟元素的子元素<a>移除"current"样式
    .next().hide(); //它们的下一个元素隐藏
    return false;
    }); 
    });
    </script>

    /* reset */
    body{margin:0;padding:0 0 12px 0;font-size:12px;line-height:22px;font-family:"\5b8b\4f53","arial narrow";background:#fff;}
    form,ul,li,p,h1,h2,h3,h4,h5,h6{margin:0;padding:0;}
    input,select{font-size:12px;line-height:16px;}
    img{border:0;}
    ul,li{list-style-type:none;}
    a {color:#00007f;text-decoration:none;}
    a:hover {color:#bd0a01;text-decoration:underline;}
    
    .box {
    width: 150px;
    margin: 0 auto;
    }
    .menu{
    overflow:hidden;
    border-color: #c4d5df;
    border-style: solid;
    border-width: 0 1px 1px;
    }
    /* lv1 */
    .menu li.level1 a{
    display: block;
    height: 28px;
    line-height: 28px;
    background:#ebf3f8;
    font-weight:700;
    color: #5893b7;
    text-indent: 14px;
    border-top: 1px solid #c4d5df;
    }
    .menu li.level1 a:hover{text-decoration:none;}
    .menu li.level1 a.current{background:#b1d7ef;}
    /* lv2 */
    .menu li ul{overflow:hidden;}
    .menu li ul.level2{display:none;}
    .menu li ul.level2 li a{
    display: block;
    height: 28px;
    line-height: 28px;
    background:#ffffff;
    font-weight:400;
    color: #42556b;
    text-indent: 18px;
    border-top: 0px solid #ffffff;
    overflow: hidden;
    }
    .menu li ul.level2 li a:hover{
    color:#f60;
    }

    <script type="text/javascript"> 
    $(document).ready(function(){ 
    $(".level2 a").each(function(){ 
    $this = $(this); 
    if($this[0].href==string(window.location)){ 
    $this.addclass("hover"); 
    } 
    }); 
    }); 
    </script>

    简单的jquery左侧导航栏和页面选中效果