用JS做的簡單的可摺疊的兩級樹形選單

NO IMAGE

複製程式碼 程式碼如下:
<!DOCTYPEhtml PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html>
<hrad>
<metahttp-equiv=”content-type”content=”text/html;charset=utf-8″>
<title>可摺疊的兩級選單</title>
<styletype=”text/css”>
<!–
body{
background-color:#ffdee0;
}
#navigation {
width:200px;
font-family:Arial;
}
#navigation > ul {
list-style-type:none;
margin:0px;
padding:0px;
}
#navigation > ul >li {
border-bottom:1pxsolid #ED9F9F;
}
#navigation > ul >li > a{
display:block;
padding:5px5px 5px 0.5em;
text-decoration:none;
border-left:12pxsolid #711515;
border-right:1pxsolid #711515;
}
#navigation > ul >li > a:link, #navigation >ul >li > a:visited{
background-color:#c11136;
color:#FFFFFF;
}
#navigation > ul >li > a:hover{
background-color:#990020;
color:#ffff00;
}
.txt{
background-color:#c11136;
color:#FFFFFF;
padding:5px5px 5px 0.5em;
text-decoration:none;
border-left:12pxsolid #711515;
border-right:1pxsolid #711515;
}

/* 子選單的CSS樣式 */
#navigation ul li ul{
list-style-type:none;
margin:0px;
padding:0px0px 0px 0px;
}
#navigation ul li ulli{
border-top:1pxsolid #ED9F9F;
}
#navigation ul li ulli a{
display:block;
padding:3px3px 3px 0.5em;
text-decoration:none;
border-left:28pxsolid #a71f1f;
border-right:1pxsolid #711515;
}
#navigation ul li ulli a:link, #navigationul li ul lia:visited{
background-color:#e85070;
color:#FFFFFF;
}
#navigation ul li ulli a:hover{
background-color:#c2425d;
color:#ffff00;
}
#navigation ul li ul.myHide{ /* 隱藏子選單 */
display:none;
}
#navigation ul li ul.myShow{ /* 顯示子選單 */
display:block;
}
–>
</style>
<scriptlanguage=”javascript”>
window.onload=function(){
varlistUL=document.getElementById(“listUL”);
varolist=listUL.childNodes;
varoa=0;
for(var i = 0; i < olist.length; i ) {
if(olist[i].tagName==”LI”&&olist[i].getElementsByTagName(“ul”)[0]){
oa=olist[i];
oa.onclick=change;
}

}
functionchange(){
varos=this.getElementsByTagName(“ul”)[0];
if(os.className==”myHide”)
os.className=”myShow”;
else
os.className=”myHide”;
}
}
</script>
</hrad>
<body>
<divid=”navigation”>
<ulid=”listUL”>
<li>
<divclass=”txt”>Home</div>
</li>
<li>
<divclass=”txt”>news</div>
<ulclass=”myHide”>
<li><ahref=”#”>lastest news</a></li>
<li><ahref=”#”>all news</a></li>
</ul>
</li>
<li>
<divclass=”txt”>sports</div>
<ulclass=”myHide”>
<li><ahref=”#”>lastest news</a></li>
<li><ahref=”#”>all news</a></li>
</ul>
</li>
<li>
<divclass=”txt”>weather</div>
<ulclass=”myHide”>
<li><ahref=”#”>lastest news</a></li>
<li><ahref=”#”>all news</a></li>
</ul>
</li>
</ul>
</div>
</body>
</html>

您可能感興趣的文章:

一個簡單的js樹形選單JS無限極樹形選單,json格式、陣列格式通用示例json jQuery實現的無限級樹形選單效果程式碼Bootstrap樹形選單外掛TreeView.js使用方法詳解Vue.js元件tree實現無限級樹形選單JS CSS實現TreeMenu二級樹形選單完整例項JS CSS簡單樹形選單實現方法javascript實現在下拉選單中顯示多級樹形選單的方法Vue.js 遞迴元件實現樹形選單(例項分享)JavaScript實現簡單的樹形選單效果