<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>树形导航</title>
<style>
a{
text-decoration: none;
}
ul{
list-style: none;
}
.treeNode li{
margin: 3px 0px 3px -20px;
white-space:nowrap;
}
.treeIcon{
border:1px solid #ccc;
}
.treeIconNo{
border: 1px solid #fff;
}
</style>
</head>
<body>
<ul class="treeNode">
<li>
<div class="treeList">
<a href="javascript:void(0)" class="treeIcon">-</a>
<a href="javascript:void(0)">1点</a>
</div>
<ul class="treeNode">
<li>
<div class="treeList">
<a href="javascript:void(0)" class="treeIcon">-</a>
<a href="javascript:void(0)">1-2点</a>
</div>
<ul class="treeNode">
<li>
<div class="treeList">
<a href="javascript:void(0)" class="treeIcon">-</a>
<a href="javascript:void(0)">1-2-1点</a>
</div>
<ul class="treeNode">
<li>
<div class="treeList">
<a href="javascript:void(0)" class="treeIconNo"> </a>
<a href="javascript:void(0)">1-2-1-1点</a>
</div>
<ul></ul>
</li>
</ul>
</li>
</ul>
</li>
<li>
<div class="treeList">
<a href="javascript:void(0)" class="treeIconNo"> </a>
<a href="javascript:void(0)">1-3点</a>
</div>
</li>
<li>
<div class="treeList">
<a href="javascript:void(0)" class="treeIconNo"> </a>
<a href="javascript:void(0)">1-4点</a>
</div>
</li>
<li>
<div class="treeList">
<a href="javascript:void(0)" class="treeIconNo"> </a>
<a href="javascript:void(0)">1-5点</a>
</div>
</li>
<li>
<div class="treeList">
<a href="javascript:void(0)" class="treeIconNo"> </a>
<a href="javascript:void(0)">1-6点</a>
</div>
<ul class="treeNode">
<li>
<div class="treeList">
<a href="javascript:void(0)" class="treeIconNo"> </a>
<a href="javascript:void(0)">1-6-1点</a>
</div>
</li>
<li>
<div class="treeList">
<a href="javascript:void(0)" class="treeIconNo"> </a>
<a href="javascript:void(0)">1-6-2点</a>
</div>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<script type="text/javascript">
window.onload = function(){
function getTypeElement(es,type) {
var eArr = [],
esl = null;
for(i = 0;i<es.length;i++){
esl = es[i];
if(esl.nodeName.replace("#","").toLocaleLowerCase() == type){
eArr.push(esl);
}
}
return eArr;
}
function treeMenuNav() {
var as = document.getElementsByTagName('a'),
ao = null;
for(var ai = 0,; ai<as.length; ai++){
ao = as[ai];
if(ao.className == "treeIcon"){
ao.onclick = function(){
var iconType = this.innerHTML,
uls = getTypeElement(this.parentNode.parentNode.childNodes,"ul"),
uli = 0,
ull = uls.length,
dis = "block";
if (iconType == "-"){
this.innerHTML = "+";
dis = "none";
}else{
this.innerHTML = "-";
}
for(; uli <ull;uli++){
uls[uli].style.display = dis;
}
}
}
}
}
treeMenuNav();
}
</script>
</body>
</html>
树形导航
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 问题描述: App当中会有原生导航栏页面与自定义导航栏页面相互切换的场景,切换当中后一个页面导航栏部分会有黑色阴影...