用jQuery写的简单两级树形菜单

<!DOCTYPE html>
<HTML>
<HEAD>
    <TITLE> treeMenu</TITLE>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="../../work/css/bootstrap.min.css">
    <script src="../../work/js/jquery.js"></script>
    <style type="text/css">
        /*矢量图标路径,阿里图标库引入*/
        @font-face {font-family: 'iconfont';
            src: url('../fonts/iconfont.eot'); /* IE9*/
            src: url('../fonts/iconfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
            url('../fonts/iconfont.woff') format('woff'), /* chrome、firefox */
            url('../fonts/iconfont.ttf') format('truetype'), /* chrome、firefox、opera、Safari, Android, iOS 4.2+*/
            url('../fonts/iconfont.svg#iconfont') format('svg'); /* iOS 4.1- */
        }
        .iconfont{font-family:"iconfont";
            font-size:16px;font-style:normal;}
        .treeMenu{
            border-bottom: 1px solid cornflowerblue;
            border-bottom: none;
            width: 20%;
        }
        .treeMenu>ul{margin: 0;padding: 0;}
        .treeMenu>.treeMenuUl>.firstMenu{
            font-weight: bold;
            font-size: 16px;
            color: #1166A2;
            padding: 10px 30px 10px 0;
            margin-top: -1px;
            cursor: pointer;
            border: 1px solid cornflowerblue;
            text-align: center;
        }
        .treeMenu>.treeMenuUl>.firstMenu:hover{
            background-color: #F8F6F6;
            color: #3218CD;
        }
        .treeMenu>.treeMenuUl>.firstMenu>.treeMenuIcon{
            font-weight: normal;
            font-size: large;
            position: relative;
            right: 50px;
        }
        .treeMenu>ul>li {
            list-style: none;
            border: 1px solid cornflowerblue;
            border-bottom: none;
            position: relative;
            height: 40px;
            line-height: 40px;
            text-align: center;
            display: none;
            margin-left: 50px;
        }
    </style>
    <script type="text/javascript">
        $(function(){
            $(".treeMenuUl").each(function(){
                var i=0;
                $(this).children(".firstMenu").click(function(){
                    if(i==1){
                        $(this).siblings().css("border","none");
                        $(this).siblings().slideUp(300);
                        $(this).children(".treeMenuIcon").html("&#xe628;");
                        if($(this).parent().next("ul").size()==0)
                        {
                            $(".treeMenu").css("borderBottom","none");
                        }
                        i=0;
                    }else{
                        $(this).siblings().slideDown(300);
                        $(this).siblings().css("border","1px solid cornflowerblue");
                        $(this).next().css("borderTop","none");
                        $(this).siblings().css("borderBottom","none");
                        $(this).children(".treeMenuIcon").html("&#xe620;");
                        if($(this).parent().next("ul").size()==0)
                        {
                            $(".treeMenu").css("borderBottom","1px solid cornflowerblue");
                        }
                        i=1;
                    }

                })
            })
        })
    </script>
</HEAD>
<BODY>
<div class="treeMenu">
    <ul class="treeMenuUl">
        <div class="firstMenu"><span class='iconfont treeMenuIcon'>&#xe628;</span>一级菜单</div>
        <li><a href="#">二级菜单</a></li>
        <li><a>二级菜单</a></li>
        <li><a>二级菜单</a></li>
        <li><a>二级菜单</a></li>
    </ul>
    <ul class="treeMenuUl">
        <div class="firstMenu"><span class='iconfont treeMenuIcon'>&#xe628;</span>一级菜单</div>
        <li><a href="#">二级菜单</a></li>
        <li><a>二级菜单</a></li>
        <li><a>二级菜单</a></li>
        <li><a>二级菜单</a></li>
    </ul>
    <ul class="treeMenuUl">
        <div class="firstMenu"><span class='iconfont treeMenuIcon'>&#xe628;</span>一级菜单</div>
        <li><a>二级菜单</a></li>
        <li><a>二级菜单</a></li>
        <li><a>二级菜单</a></li>
        <li><a>二级菜单</a></li>
    </ul>
</div>
</BODY>
</HTML>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值