网页折叠菜单

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了网页折叠菜单相关的知识,希望对你有一定的参考价值。

那位高手能详细地给以下代码上注释 和添加菜单的下滑时间功能 我给你加分
(注释要求详细 加上的功能代码要简洁)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>每次只展开一组的折叠菜单</title>
<style type="text/css">
* margin:0px; padding:0px; border:0px;
body font-size:12px; color:#333;text-align:center;
.ztbox background:#fff;
.ztboxtext-align:left;width:220px;height:auto;border:solid 1px #2173f7;margin:10px auto 0px;overflow: hidden;position: absolute;left: 10px;top: 0px;
.ztbox h2font-size:14px;height:22px;line-height:22px;background:#c6d5ff;text-indent:10px;position:relative;border-top: 1px solid #fff;border-bottom: 1px solid #2173f7; font-weight:normal;cursor:pointer;
.ztbox h2 spanfont-weight: normal;position:absolute;top:0;right:6px;
.ztbox liborder-bottom:dashed 1px #eee;
.ztbox border-bottom:solid 1px #2173f7;
.ztlist list-style:disc url(none); margin:6px 10px 6px 20px;
</style>
</head>
<body>
<div id="ztbox" class="ztbox" style="left: 10px; width: 149px;">
<h2 id="t1" onclick="ShHi('t1','h1');">
标题1
</h2>
<ul class="ztlist" id="h1" style="display:none;">
<li>
这里可以放很多的内容...
</li>
</ul>
<h2 id="t2" onclick="ShHi('t2','h2');">
标题2
</h2>
<ul class="ztlist" id="h2" style="display:none;">
<li>
这里可以放很多的内容...
</li>
</ul>
</div>
<script type="text/javascript">
var clickul,clickh;
function $(d)return document.getElementById(d);
function f(d)
var t=$(d);if (t)return t.style;
else
return null;


function Hi()
if(clickul)clickul.style.display='none';

function Hl()
if(clickh)clickh.style.fontWeight='normal';

function h(d)
var s=f(d);
var b=s.display;
if (b=='none')
return true;
else
return false;


function ShHi(ii,jj)
if(h(jj))
Hi();
Hl();
f(jj).display='block';
f(ii).fontWeight='bold';
clickul=$(jj);clickh=$(ii);
else
Hi();
Hl();
f(jj).display='none';
f(ii).fontWeight='normal';
clickul=null;clickh=null;

</script></body></html>
刷新 滑块不闭合
请不要只提示我去看文档好吗。
文档我在看,就是很多看不明白的,如果那位大侠能 帮我完成我的提问的 小弟感激不尽 和给你加多多的分
下滑时间功能指的是点击菜单时菜单慢慢地展开

参考技术A <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>每次只展开一组的折叠菜单</title>
<style type="text/css">
* margin:0px; padding:0px; border:0px;
body font-size:12px; color:#333;text-align:center;
.ztbox background:#fff;
.ztboxtext-align:left;width:220px;height:auto;border:solid 1px #2173f7;margin:10px auto 0px;overflow: hidden;position: absolute;left: 10px;top: 0px;
.ztbox h2font-size:14px;height:22px;line-height:22px;background:#c6d5ff;text-indent:10px;position:relative;border-top: 1px solid #fff;border-bottom: 1px solid #2173f7; font-weight:normal;cursor:pointer;
.ztbox h2 spanfont-weight: normal;position:absolute;top:0;right:6px;
.ztbox liborder-bottom:dashed 1px #eee;
.ztbox border-bottom:solid 1px #2173f7;
.ztlist list-style:disc url(none); margin:6px 10px 6px 20px;
</style>
</head>
<body>
<div id="ztbox" class="ztbox" style="left: 10px; width: 149px;">
<h2 id="t1" onclick="ShHi('t1','h1');">
标题1
</h2>
<ul class="ztlist" id="h1" style="display:none;">
<li>
这里可以放很多的内容...
</li>
</ul>
<h2 id="t2" onclick="ShHi('t2','h2');">
标题2
</h2>
<ul class="ztlist" id="h2" style="display:none;">
<li>
这里可以放很多的内容...
</li>
</ul>
</div>
<script type="text/javascript">
var clickul,clickh;
function $(d)return document.getElementById(d);//这里声明一个$函数简化了代替了getElementById,以后$('aa')就相当于docudocument.getElementById('aa');
function f(d)//这个方法用来获得DHTMLElement的style属性(style属性和CSS的是对应的)如果没有这样ID的DHTMLElement则返回空值
var t=$(d);if (t)return t.style;
else
return null;


function Hi()//隐藏
if(clickul)clickul.style.display='none';

function Hl()//把层的字体变回正常
if(clickh)clickh.style.fontWeight='normal';

function h(d)//判断这个DHTMLElement是不是隐藏的
var s=f(d);
var b=s.display;
if (b=='none')
return true;
else
return false;


function ShHi(ii,jj)
if(h(jj))//判断是不是隐藏
Hi();
Hl();
f(jj).display='block';//把jj(传入来的参数)为ID的层显示出来
f(ii).fontWeight='bold';//字体变为‘BOLD’
clickul=$(jj);clickh=$(ii);
else//如果JJ不隐藏,执行下面的
Hi();
Hl();
f(jj).display='none';//隐藏
f(ii).fontWeight='normal';//字体变回正常
clickul=null;clickh=null;

</script></body></html>
不明白“和添加菜单的下滑时间功能”是什么功能
所以没有写
任何疑问:
blog.csdn.net/shmilyhe

shmilyhe@163.com本回答被提问者采纳
参考技术B 这个 你还不如自己去看看JS帮助文档~~~~~~ 参考技术C yddyffkhgkgjhlij;ojkl;

JS实现无限级网页折叠菜单(类似树形菜单)

<html>
<head>
<title>无限级折叠菜单JS版</title>
<style> 
<!--
body,ul,h3 {margin:0px; padding:0px;}
li {list-style-type:none;}
body{
 font-size:12px;
 color:#333; 
 font-family: Simsun;
 line-height:15px;
 }
a{text-decoration:none;color:#004285;border:none;}
a:hover{text-decoration:none;color:#C33;}
#menu {
 width:260px;
 margin:50px auto; 
 padding:10px; 
 border:#EEE 1px solid;
 }
 #menu h3 {
 font-size:12px;
 }
 #menu ul { 
 background:url("images/ul-bg.gif") repeat-y 5px 0px; overflow:hidden;
 }
 #menu ul li {
 padding:5px 0 2px 15px; 
 background:url("images/tree-ul-li.gif") no-repeat 5px -32px; 
 }
 #menu ul li ul {display:none;}
 #menu ul li em {
 cursor:pointer;
 display:inline-block;
 width:15px;
 float:left;
 height:15px;
 margin-left:-14px;
 background:url("images/tree-ul-li.gif") no-repeat -32px 2px;
 }
 #menu ul li em.off {
 background-position: -17px -18px;
 }
 #menu ul li#end {
 background-color:#FFF;
 }
 #menu ul.off { 
 display:block;
 }
-->
</style>
</head>
<body>
<div id="menu">
 <h3>无限级折叠菜单JavaScript版</h3>
 <ul>
 <li><em></em><a href=‘javascript:void(0);‘>菜单_1_1</a>
 <ul>
  <li><em></em><a href=‘javascript:void(0);‘>菜单_2_1</a>
  <ul>
  <li><em></em><a href=‘javascript:void(0);‘>菜单_3_1</a>
  <ul>
   <li><em></em><a href=‘javascript:void(0);‘>菜单_4_1</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
   <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_4_2</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
  </ul>
  </li>
  <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_3_2</a>
  <ul>
   <li><em></em><a href=‘javascript:void(0);‘>菜单_4_1</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
   <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_4_2</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
  </ul>
  </li>
  </ul>
  </li>
  <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_2_2</a>
  <ul>
  <li><em></em><a href=‘javascript:void(0);‘>菜单_3_1</a>
  <ul>
   <li><em></em><a href=‘javascript:void(0);‘>菜单_4_1</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
   <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_4_2</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
  </ul>
  </li>
  <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_3_2</a>
  <ul>
   <li><em></em><a href=‘javascript:void(0);‘>菜单_4_1</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
   <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_4_2</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
  </ul>
  </li>
  </ul>
  </li>
 </ul>
 </li>
 <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_1_2</a>
 <ul>
  <li><em></em><a href=‘javascript:void(0);‘>菜单_2_1</a>
  <ul>
  <li><em></em><a href=‘javascript:void(0);‘>菜单_3_1</a>
  <ul>
   <li><em></em><a href=‘javascript:void(0);‘>菜单_4_1</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
   <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_4_2</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
  </ul>
  </li>
  <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_3_2</a>
  <ul>
   <li><em></em><a href=‘javascript:void(0);‘>菜单_4_1</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
   <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_4_2</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
  </ul>
  </li>
  </ul>
  </li>
  <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_2_2</a>
  <ul>
  <li><em></em><a href=‘javascript:void(0);‘>菜单_3_1</a>
  <ul>
   <li><em></em><a href=‘javascript:void(0);‘>菜单_4_1</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
   <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_4_2</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
  </ul>
  </li>
  <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_3_2</a>
  <ul>
   <li><em></em><a href=‘javascript:void(0);‘>菜单_4_1</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
   <li id=‘end‘><em></em><a href=‘javascript:void(0);‘>菜单_4_2</a>
   <ul>
   <li><a href=‘javascript:void(0);‘>菜单_5_1</a></li>
   <li id=‘end‘><a href=‘javascript:void(0);‘>菜单_5_2</a></li>
   </ul>
   </li>
  </ul>
  </li>
  </ul>
  </li>
 </ul>
 </li>
 </ul>
</div>
<script type="text/javascript"> 
(function(e){
 for(var _obj=document.getElementById(e.id).getElementsByTagName(e.tag),i=-1,em;em=_obj[++i];){
 em.onclick = function(){ //onmouseover
  var ul = this.nextSibling;
  if(!ul){return false;}
  ul = ul.nextSibling; if(!ul){return false;} 
  if(e.tag != a){ ul = ul.nextSibling; if(!ul){return false;} } //a 标签控制 隐藏或删除该行
  for(var _li=this.parentNode.parentNode.childNodes,n=-1,li;li=_li[++n];){
  if(li.tagName=="LI"){
   for(var _ul=li.childNodes,t=-1,$ul;$ul=_ul[++t];){
   switch($ul.tagName){
   case "UL":
    $ul.className = $ul!=ul?"" : ul.className?"":"off";
   break;
   case "EM":
    $ul.className = $ul!=this?"" : this.className?"":"off";
   break;
   }
   }
  }
  }
 }
 }
})({id:menu,tag:em});
</script>
</body>
</html>

 

以上是关于网页折叠菜单的主要内容,如果未能解决你的问题,请参考以下文章

asp.net 折叠菜单,我想做一个网页左边是折叠菜单,点击左边右边出现内容的那种折叠式菜单

JS实现无限级网页折叠菜单(类似树形菜单)

折叠的菜单不起作用

ASP动态网页设计与Ajax技术----制作折叠式菜单

CSS3 3D折叠菜单导航

求一个 HTML的竖向折叠菜单 源码