本文实例讲述了JS实现三级折叠菜单特效,其它级可自动收缩。分享给大家供大家参考,很实用,在IE6、IE7、IE8、FF、chrome等浏览器都正常运行具体如下:
小贴士:去掉CSS中 #menu ul中 {height:100px; overflow:auto;} 即可高度自适应
运行效果图如下:
实现代码如下:
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>三级折叠菜单</title> <style> *,body,ul,h1,h2{ margin:0; padding:0; list-style:none;} body{font:12px "宋体"; padding-top:20px;} a{ color:#777;border:none;} #menu { width:200px; margin:auto;} #menu h1 { font-size:12px; border:#C60 1px solid; margin-top:1px; background-color:#F93;} #menu h2 { font-size:12px; border:#E7E7E7 1px solid; border-top-color:#FFF; background-color:#F4F4F4;} #menu ul { padding-left:15px; height:100px;border:#E7E7E7 1px solid; border-top:none;overflow:auto;} #menu a { display:block; padding:5px 0 3px 10px; text-decoration:none; overflow:hidden;} #menu a:hover{ color:#6F0; background:#000;} #menu .no {display:none;} #menu .h1 a{color:#6F0;} #menu .h2 a{color:#06F;} #menu h1 a{color:#FFF;} </style> <script language="JavaScript"> <!--// function ShowMenu(obj,n){ var Nav = obj.parentNode; if(!Nav.id){ var BName = Nav.getElementsByTagName("ul"); var HName = Nav.getElementsByTagName("h2"); var t = 2; }else{ var BName = document.getElementById(Nav.id).getElementsByTagName("span"); var HName = document.getElementById(Nav.id).getElementsByTagName("h1"); var t = 1; } for(var i=0; i<HName.length;i++){ HName[i].innerHTML = HName[i].innerHTML.replace("-","+"); HName[i].className = ""; } obj.className = "h" + t; for(var i=0; i<BName.length; i++){if(i!=n){BName[i].className = "no";}} if(BName[n].className == "no"){ BName[n].className = ""; obj.innerHTML = obj.innerHTML.replace("+","-"); }else{ BName[n].className = "no"; obj.className = ""; obj.innerHTML = obj.innerHTML.replace("-","+"); } } //--> </script> </head> <body> <div id="menu"> <h1 onClick="javascript:ShowMenu(this,0)"><a href="javascript:void(0)">+ 一级菜单A</a></a></h1> <span class="no"> <h2 onClick="javascript:ShowMenu(this,0)"><a href="javascript:void(0)">+ 一级菜单A_1</a></a></h2> <ul class="no"> <a href="javascript:void(0)">一级菜单A_0</a> <a href="javascript:void(0)">一级菜单A_1</a> <a href="javascript:void(0)">一级菜单A_2</a> <a href="javascript:void(0)">一级菜单A_3</a> <a href="javascript:void(0)">一级菜单A_4</a> <a href="javascript:void(0)">一级菜单A_5</a> <a href="javascript:void(0)">一级菜单A_6</a> <a href="javascript:void(0)">一级菜单A_7</a> <a href="javascript:void(0)">一级菜单A_8</a> <a href="javascript:void(0)">一级菜单A_9</a> </ul> <h2 onClick="javascript:ShowMenu(this,1)"><a href="javascript:void(0)">+ 一级菜单A_2</a></h2> <ul class="no"> <a href="javascript:void(0)">一级菜单A_0</a> <a href="javascript:void(0)">一级菜单A_1</a> <a href="javascript:void(0)">一级菜单A_2</a> <a href="javascript:void(0)">一级菜单A_3</a> <a href="javascript:void(0)">一级菜单A_4</a> <a href="javascript:void(0)">一级菜单A_5</a> <a href="javascript:void(0)">一级菜单A_6</a> <a href="javascript:void(0)">一级菜单A_7</a> <a href="javascript:void(0)">一级菜单A_8</a> <a href="javascript:void(0)">一级菜单A_9</a> </ul> <h2 onClick="javascript:ShowMenu(this,2)"><a href="javascript:void(0)">+ 一级菜单A_3</a></h2> <ul class="no"> <a href="javascript:void(0)">一级菜单A_0</a> <a href="javascript:void(0)">一级菜单A_1</a> <a href="javascript:void(0)">一级菜单A_2</a> <a href="javascript:void(0)">一级菜单A_3</a> <a href="javascript:void(0)">一级菜单A_4</a> <a href="javascript:void(0)">一级菜单A_5</a> <a href="javascript:void(0)">一级菜单A_6</a> <a href="javascript:void(0)">一级菜单A_7</a> <a href="javascript:void(0)">一级菜单A_8</a> <a href="javascript:void(0)">一级菜单A_9</a> </ul> <h2 onClick="javascript:ShowMenu(this,3)"><a href="javascript:void(0)">+ 一级菜单A_4</a></h2> <ul class="no"> <a href="javascript:void(0)">一级菜单A_0</a> <a href="javascript:void(0)">一级菜单A_1</a> <a href="javascript:void(0)">一级菜单A_2</a> <a href="javascript:void(0)">一级菜单A_3</a> <a href="javascript:void(0)">一级菜单A_4</a> <a href="javascript:void(0)">一级菜单A_5</a> <a href="javascript:void(0)">一级菜单A_6</a> <a href="javascript:void(0)">一级菜单A_7</a> <a href="javascript:void(0)">一级菜单A_8</a> <a href="javascript:void(0)">一级菜单A_9</a> </ul> <h2 onClick="javascript:ShowMenu(this,4)"><a href="javascript:void(0)">+ 一级菜单A_5</a></h2> <ul class="no"> <a href="javascript:void(0)">一级菜单A_0</a> <a href="javascript:void(0)">一级菜单A_1</a> <a href="javascript:void(0)">一级菜单A_2</a> <a href="javascript:void(0)">一级菜单A_3</a> <a href="javascript:void(0)">一级菜单A_4</a> <a href="javascript:void(0)">一级菜单A_5</a> <a href="javascript:void(0)">一级菜单A_6</a> <a href="javascript:void(0)">一级菜单A_7</a> <a href="javascript:void(0)">一级菜单A_8</a> <a href="javascript:void(0)">一级菜单A_9</a> </ul> <h2 onClick="javascript:ShowMenu(this,5)"><a href="javascript:void(0)">+ 一级菜单A_6</a></h2> <ul class="no"> <a href="javascript:void(0)">一级菜单A_0</a> <a href="javascript:void(0)">一级菜单A_1</a> <a href="javascript:void(0)">一级菜单A_2</a> <a href="javascript:void(0)">一级菜单A_3</a> <a href="javascript:void(0)">一级菜单A_4</a> <a href="javascript:void(0)">一级菜单A_5</a> <a href="javascript:void(0)">一级菜单A_6</a> <a href="javascript:void(0)">一级菜单A_7</a> <a href="javascript:void(0)">一级菜单A_8</a> <a href="javascript:void(0)">一级菜单A_9</a> </ul> <h2 onClick="javascript:ShowMenu(this,6)"><a href="javascript:void(0)">+ 一级菜单A_7</a></h2> <ul class="no"> <a href="javascript:void(0)">一级菜单A_0</a> <a href="javascript:void(0)">一级菜单A_1</a> <a href="javascript:void(0)">一级菜单A_2</a> <a href="javascript:void(0)">一级菜单A_3</a> <a href="javascript:void(0)">一级菜单A_4</a> <a href="javascript:void(0)">一级菜单A_5</a> <a href="javascript:void(0)">一级菜单A_6</a> <a href="javascript:void(0)">一级菜单A_7</a> <a href="javascript:void(0)">一级菜单A_8</a> <a href="javascript:void(0)">一级菜单A_9</a> </ul> <h2 onClick="javascript:ShowMenu(this,7)"><a href="javascript:void(0)">+ 一级菜单A_8</a></h2> <ul class="no"> <a href="javascript:void(0)">一级菜单A_0</a> <a href="javascript:void(0)">一级菜单A_1</a> <a href="javascript:void(0)">一级菜单A_2</a> <a href="javascript:void(0)">一级菜单A_3</a> <a href="javascript:void(0)">一级菜单A_4</a> <a href="javascript:void(0)">一级菜单A_5</a> <a href="javascript:void(0)">一级菜单A_6</a> <a href="javascript:void(0)">一级菜单A_7</a> <a href="javascript:void(0)">一级菜单A_8</a> <a href="javascript:void(0)">一级菜单A_9</a> </ul> <h2 onClick="javascript:ShowMenu(this,8)"><a href="javascript:void(0)">+ 一级菜单A_9</a></h2> <ul class="no"> <a href="javascript:void(0)">一级菜单A_0</a> <a href="javascript:void(0)">一级菜单A_1</a> <a href="javascript:void(0)">一级菜单A_2</a> <a href="javascript:void(0)">一级菜单A_3</a> <a href="javascript:void(0)">一级菜单A_4</a> <a href="javascript:void(0)">一级菜单A_5</a> <a href="javascript:void(0)">一级菜单A_6</a> <a href="javascript:void(0)">一级菜单A_7</a> <a href="javascript:void(0)">一级菜单A_8</a> <a href="javascript:void(0)">一级菜单A_9</a> </ul> <h2 onClick="javascript:ShowMenu(this,9)"><a href="javascript:void(0)">+ 一级菜单A_10</a></h2> <ul class="no"> <a href="javascript:void(0)">一级菜单A_0</a> <a href="javascript:void(0)">一级菜单A_1</a> <a href="javascript:void(0)">一级菜单A_2</a> <a href="javascript:void(0)">一级菜单A_3</a> <a href="javascript:void(0)">一级菜单A_4</a> <a href="javascript:void(0)">一级菜单A_5</a> <a href="javascript:void(0)">一级菜单A_6</a> <a href="javascript:void(0)">一级菜单A_7</a> <a href="javascript:void(0)">一级菜单A_8</a> <a href="javascript:void(0)">一级菜单A_9</a> </ul> <h2 onClick="javascript:ShowMenu(this,10)"><a href="javascript:void(0)">+ 一级菜单A_11</a></h2> <ul class="no"> <a href="javascript:void(0)">一级菜单A_0</a> <a href="javascript:void(0)">一级菜单A_1</a> <a href="javascript:void(0)">一级菜单A_2</a> <a href="javascript:void(0)">一级菜单A_3</a> <a href="javascript:void(0)">一级菜单A_4</a> <a href="javascript:void(0)">一级菜单A_5</a> <a href="javascript:void(0)">一级菜单A_6</a> <a href="javascript:void(0)">一级菜单A_7</a> <a href="javascript:void(0)">一级菜单A_8</a> <a href="javascript:void(0)">一级菜单A_9</a> </ul> <h2 onClick="javascript:ShowMenu(this,11)"><a href="javascript:void(0)">+ 一级菜单A_12</a></h2> <ul class="no"> <a href="javascript:void(0)">一级菜单A_0</a> <a href="javascript:void(0)">一级菜单A_1</a> <a href="javascript:void(0)">一级菜单A_2</a> <a href="javascript:void(0)">一级菜单A_3</a> <a href="javascript:void(0)">一级菜单A_4</a> <a href="javascript:void(0)">一级菜单A_5</a> <a href="javascript:void(0)">一级菜单A_6</a> <a href="javascript:void(0)">一级菜单A_7</a> <a href="javascript:void(0)">一级菜单A_8</a> <a href="javascript:void(0)">一级菜单A_9</a> </ul> </span> <h1 onClick="javascript:ShowMenu(this,1)"><a href="javascript:void(0)">+ 二级菜单B</a></h1> <span class="no"> <h2 onClick="javascript:ShowMenu(this,0)"><a href="javascript:void(0)">+ 二级菜单B_1</a></h2> <ul class="no"> <a href="javascript:void(0)">二级菜单B_0</a> <a href="javascript:void(0)">二级菜单B_1</a> <a href="javascript:void(0)">二级菜单B_2</a> <a href="javascript:void(0)">二级菜单B_3</a> <a href="javascript:void(0)">二级菜单B_4</a> <a href="javascript:void(0)">二级菜单B_5</a> <a href="javascript:void(0)">二级菜单B_6</a> <a href="javascript:void(0)">二级菜单B_7</a> <a href="javascript:void(0)">二级菜单B_8</a> <a href="javascript:void(0)">二级菜单B_9</a> </ul> <h2 onClick="javascript:ShowMenu(this,1)"><a href="javascript:void(0)">+ 二级菜单B_2</a></h2> <ul class="no"> <a href="javascript:void(0)">二级菜单B_0</a> <a href="javascript:void(0)">二级菜单B_1</a> <a href="javascript:void(0)">二级菜单B_2</a> <a href="javascript:void(0)">二级菜单B_3</a> <a href="javascript:void(0)">二级菜单B_4</a> <a href="javascript:void(0)">二级菜单B_5</a> <a href="javascript:void(0)">二级菜单B_6</a> <a href="javascript:void(0)">二级菜单B_7</a> <a href="javascript:void(0)">二级菜单B_8</a> <a href="javascript:void(0)">二级菜单B_9</a> </ul> </span> <h1 onClick="javascript:ShowMenu(this,2)"><a href="javascript:void(0)">+ 三级菜单C</a></h1> <span class="no"> <h2 onClick="javascript:ShowMenu(this,0)"><a href="javascript:void(0)">+ 三级菜单C_1</a></h2> <ul class="no"> <a href="javascript:void(0)">三级菜单C_0</a> <a href="javascript:void(0)">三级菜单C_1</a> <a href="javascript:void(0)">三级菜单C_2</a> <a href="javascript:void(0)">三级菜单C_3</a> <a href="javascript:void(0)">三级菜单C_4</a> <a href="javascript:void(0)">三级菜单C_5</a> <a href="javascript:void(0)">三级菜单C_6</a> <a href="javascript:void(0)">三级菜单C_7</a> <a href="javascript:void(0)">三级菜单C_8</a> <a href="javascript:void(0)">三级菜单C_9</a> </ul> <h2 onClick="javascript:ShowMenu(this,1)"><a href="javascript:void(0)">+ 三级菜单C_2</a></h2> <ul class="no"> <a href="javascript:void(0)">三级菜单C_0</a> <a href="javascript:void(0)">三级菜单C_1</a> <a href="javascript:void(0)">三级菜单C_2</a> <a href="javascript:void(0)">三级菜单C_3</a> <a href="javascript:void(0)">三级菜单C_4</a> <a href="javascript:void(0)">三级菜单C_5</a> <a href="javascript:void(0)">三级菜单C_6</a> <a href="javascript:void(0)">三级菜单C_7</a> <a href="javascript:void(0)">三级菜单C_8</a> <a href="javascript:void(0)">三级菜单C_9</a> </ul> </span> <h1 onClick="javascript:ShowMenu(this,3)"><a href="javascript:void(0)">+ 四级菜单D</a></h1> <span class="no"> <h2 onClick="javascript:ShowMenu(this,0)"><a href="javascript:void(0)">+ 四级菜单D_1</a></h2> <ul class="no"> <a href="javascript:void(0)">四级菜单D_0</a> <a href="javascript:void(0)">四级菜单D_1</a> <a href="javascript:void(0)">四级菜单D_2</a> <a href="javascript:void(0)">四级菜单D_3</a> <a href="javascript:void(0)">四级菜单D_4</a> <a href="javascript:void(0)">四级菜单D_5</a> <a href="javascript:void(0)">四级菜单D_6</a> <a href="javascript:void(0)">四级菜单D_7</a> <a href="javascript:void(0)">四级菜单D_8</a> <a href="javascript:void(0)">四级菜单D_9</a> </ul> <h2 onClick="javascript:ShowMenu(this,1)"><a href="javascript:void(0)">+ 四级菜单D_2</a></h2> <ul class="no"> <a href="javascript:void(0)">四级菜单D_0</a> <a href="javascript:void(0)">四级菜单D_1</a> <a href="javascript:void(0)">四级菜单D_2</a> <a href="javascript:void(0)">四级菜单D_3</a> <a href="javascript:void(0)">四级菜单D_4</a> <a href="javascript:void(0)">四级菜单D_5</a> <a href="javascript:void(0)">四级菜单D_6</a> <a href="javascript:void(0)">四级菜单D_7</a> <a href="javascript:void(0)">四级菜单D_8</a> <a href="javascript:void(0)">四级菜单D_9</a> </ul> </span> </div> </body> </html>
希望本文所述对大家的javascript程序设计有所帮助。
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2024年11月26日
2024年11月26日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]