<div class="codetitle"> <span><a style="CURSOR: pointer" data="93337" class="copybut" id="copybut93337" onclick="doCopy('code93337')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code93337"> <br> <br> <br> <br><title>伸缩的菜单</title> <br><style> <BR><!-- <BR>body{ <BR>background-color:#ffdee0; <BR>} <BR>#navigation { <BR>width:200px; <BR>font-family:Arial; <BR>} <BR>#navigation > ul { <BR>list-style-type:none;/* 不显示项目符号 */ <BR>margin:0px; <BR>padding:0px; <BR>} <BR>#navigation > ul > li { <BR>border-bottom:1px solid #ED9F9F;/* 添加下划线 */ <BR>} <BR>#navigation > ul > li > a{ <BR>display:block;/* 区块显示 */ <BR>padding:5px 5px 5px 0.5em; <BR>text-decoration:none; <BR>border-left:12px solid #711515;/* 左边的粗红边 */ <BR>border-right:1px solid #711515;/* 右侧阴影 */ <BR>} <BR>#navigation > ul > li > a:link, #navigation > ul > li > a:visited{ <BR>background-color:#c11136; <BR>color:#FFFFFF; <BR>} <BR>#navigation > ul > li > a:hover{ /* 鼠标经过时 */ <BR>background-color:#990020;/* 改变背景色 */ <BR>color:#ffff00;/* 改变文字颜色 */ <BR>} <br><br><BR>/* 子菜单的CSS样式 */ <BR>#navigation ul li ul{ <BR>list-style-type:none; <BR>margin:0px; <BR>padding:0px 0px 0px 0px; <BR>} <BR>#navigation ul li ul li{ <BR>border-top:1px solid #ED9F9F; <BR>} <BR>#navigation ul li ul li a{ <BR>display:block; <BR>padding:3px 3px 3px 0.5em; <BR>text-decoration:none; <BR>border-left:28px solid #a71f1f; <BR>border-right:1px solid #711515; <BR>} <BR>#navigation ul li ul li a:link, #navigation ul li ul li a:visited{ <BR>background-color:#e85070; <BR>color:#FFFFFF; <BR>} <BR>#navigation ul li ul li a:hover{ <BR>background-color:#c2425d; <BR>color:#ffff00; <BR>} <BR>#navigation ul li ul.myHide{ /* 隐藏子菜单 */ <BR>display:none; <BR>} <BR>#navigation ul li ul.myShow{ /* 显示子菜单 */ <BR>display:block; <BR>} <BR>--> <BR></style> <br><script language="javascript"> <BR>function change(){ <BR>//通过父元素li,找到兄弟元素ul <BR>var oSecondDiv = this.parentNode.getElementsByTagName("ul")[0]; <BR>//CSS交替更换来实现显、隐 <BR>if(oSecondDiv.className == "myHide") <BR>oSecondDiv.className = "myShow"; <BR>else <BR>oSecondDiv.className = "myHide"; <BR>} <BR>window.onload = function(){ <BR>var oUl = document.getElementById("listUL"); <BR>var aLi = oUl.childNodes;//子元素 <BR>var oA; <BR>for(var i=0;i<aLi.length;i++){ <BR>//如果子元素为li,且这个li有子菜单ul <BR>if(aLi[i].tagName == "LI" && aLi[i].getElementsByTagName("ul").length){ <BR>oA = aLi[i].firstChild;//找到超链接 <BR>oA.onclick = change;//动态添加点击函数 <BR>} <BR>} <BR>} <BR></script> <br> <br> <br><div id="navigation"> <br><ul id="listUL"> <br><li><a href="#">Home</a></li> <br><li> <a href="#">News</a> <br><ul class="myHide"> <br><li><a href="#">Lastest News</a></li> <br><li><a href="#">All News</a></li> <br> </ul> <br> </li> <br><li> <a href="#">Sports</a> <br><ul class="myHide"> <br><li><a href="#">Basketball</a></li> <br><li><a href="#">Football</a></li> <br><li><a href="#">Volleyball</a></li> <br> </ul> <br> </li> <br><li> <a href="#">Weather</a> <br><ul class="myHide"> <br><li><a href="#">Today's Weather</a></li> <br><li><a href="#">Forecast</a></li> <br> </ul> <br> </li> <br><li><a href="#">Contact Me</a></li> <br> </ul> <br> </div> <br> <br> <br> </div>