使用js简单实现了tree树菜单

(编辑:jimmy 日期: 2024/10/10 浏览:2)

复制代码 代码如下:
<!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="/UploadFiles/2021-04-02/jquery-1.10.2.min.js"></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简单实现了树菜单!相信自己你一定可以实现的更好!

实现的效果图
使用js简单实现了tree树菜单

一句话新闻

高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。