100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > html左侧导航栏树状 请问这种树形结构的导航栏用html或者js怎么实现?

html左侧导航栏树状 请问这种树形结构的导航栏用html或者js怎么实现?

时间:2019-12-31 17:55:47

相关推荐

html左侧导航栏树状 请问这种树形结构的导航栏用html或者js怎么实现?

满意答案

yj19791212

.04.21

采纳率:59%等级:12

已帮助:7421人

下面是最基本的框架,内容和样式你需要自己调整

#tree {

width: 150px;

}

#tree, #tree ul {

list-style: none; margin: 0; padding: 0; padding: 10px;

}

#tree li {

border: 1px solid #00f; padding: 10px; cursor: pointer;

}

#tree ul {

display: none;

}

window.onload = function() {

var tree = document.getElementById("tree");

var lis = tree.getElementsByTagName("li");

for(var i = 0; i < lis.length; i++) {

(function(a) {

lis[a].onclick = function() {

if(typeof this.getElementsByTagName("ul") !== null) {

var ul_first = this.getElementsByTagName("ul")[0];

if(ul_first.style.display == "block")

ul_first.style.display = "none";

else

ul_first.style.display = "block";

}

};

})(i);

}

};

菜单一1-11-21-31-4菜单二2-12-22-32-4菜单三3-13-23-33-4

00分享举报

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。