js 实现tree 实现树菜单

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>tree</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.node ul{
	margin-left:20px;
}
.node .node{
	display:none;
}
.node .tree{
	height:24px;
	line-height:24px;
}
.ce_ceng_close{
	background:url(images/cd_zd1.png) left center no-repeat;
	padding-left: 15px;
}
.ce_ceng_open{
	background:url(images/cd_zd.png) left center no-repeat;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
</head>

<body>
<div class="cd_zj_l">


<div class="cd_title">目录导航</div>
<div class="cv_fcv node">
	<div class="tree">哲学、宗教</div>
    <ul class="node">
        <li>
            <div class="tree">哲学伦理</div>
            <ul class="node">
                <li>
                    <div class="tree">马克思主义哲学</div>
                    <div class="tree">马克思主义哲学</div>
                    <div class="tree">马克思主义哲学</div>
                    <div class="tree">马克思主义哲学</div>
                </li>
                 <div style="clear:both"></div>
            </ul>
            
        </li>
        <div style="clear:both"></div>
    </ul>
    <div class="tree">哲学、宗教</div>
    <ul class="node">
        <li>
            <div class="tree">哲学伦理</div>
            <ul class="node">
                <li>
                    <div class="tree">马克思主义哲学</div>
                    <div class="tree">马克思主义哲学</div>
                    <div class="tree">马克思主义哲学</div>
                    <div class="tree">马克思主义哲学</div>
                </li>
            </ul>
        </li>
    </ul>
</div>
</div>
<script type="text/javascript">
	$(".tree").each(function(index, element) {
        if($(this).next(".node").length>0){
			$(this).addClass("ce_ceng_close");
		}
    });
	$(".tree").click(function(e){
		var ul = $(this).next(".node");
		if(ul.css("display")=="none"){
			ul.slideDown();
			$(this).addClass("ce_ceng_open");
			ul.find(".ce_ceng_close").removeClass("ce_ceng_open");
		}else{
			ul.slideUp();
			$(this).removeClass("ce_ceng_open");
			ul.find(".node").slideUp();
			ul.find(".ce_ceng_close").removeClass("ce_ceng_open");
		}
	});
</script>
</body>
</html>


使用js简单实现了树菜单!相信自己你一定可以实现的更好!

实现的效果图

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值