论坛首页 入门技术论坛

树型菜单

浏览 1778 次
锁定老帖子 主题:树型菜单
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-12-27  

在head 里加入代码以下
<script language=JavaScript1.2>
scores = new Array(20);
var numTotal=0;
NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
ver4 = (NS4 || IE4) ? 1 : 0;

if (ver4) {
    with (document) {
        write("<STYLE TYPE='text/css'>");
        if (NS4) {
            write(".parent {position:absolute; visibility:visible}");
            write(".child {position:absolute; visibility:visible}");
            write(".regular {position:absolute; visibility:visible}")
        }
        else {
            write(".child {display:none}")
        }
        write("</STYLE>");
    }
}

function getIndex(el) {
    ind = null;
    for (i=0; i<document.layers.length; i++) {
        whichEAl = document.layers[i];
        if (whichEl.id == el) {
            ind = i;
            break;
        }
    }
    return ind;
}

function arrange() {
    nextY = document.layers[firstInd].pageY +document.layers[firstInd].document.height;
    for (i=firstInd+1; i<document.layers.length; i++) {
        whichEl = document.layers[i];
        if (whichEl.visibility != "hide") {
            whichEl.pageY = nextY;
            nextY += whichEl.document.height;
        }
    }
}

function initIt(){
    if (!ver4) return;
    if (NS4) {
        for (i=0; i<document.layers.length; i++) {
            whichEl = document.layers[i];
            if (whichEl.id.indexOf("Child") != -1) whichEl.visibility = "hide";
       }
        arrange();
    }
    else {
        divColl = document.all.tags("DIV");
        for (i=0; i<divColl.length; i++) {
            whichEl = divColl(i);
            if (whichEl.className == "child") whichEl.style.display = "none";
        }
    }
}

function expandIt(el) {
	if (!ver4) return;
    if (IE4) {
        whichEl1 = eval(el + "Child");
		for(i=1;i<=numTotal;i++){
			whichEl = eval(scores[i] + "Child");
			if(whichEl!=whichEl1) {
				whichEl.style.display = "none";
			}
		}
        whichEl1 = eval(el + "Child");
        if (whichEl1.style.display == "none") {
            whichEl1.style.display = "block";
        }
        else {
            whichEl1.style.display = "none";
        }
    }
    else {
        whichEl = eval("document." + el + "Child");
		for(i=1;i<=numTotal;i++){
			whichEl = eval("document." + scores[i] + "Child");
			if(whichEl!=whichEl1) {
				whichEl.visibility = "hide";
			}
		}
        if (whichEl.visibility == "hide") {
            whichEl.visibility = "show";
        }
        else {
            whichEl.visibility = "hide";
        }
        arrange();
    }
}
onload = initIt;
</script>






在body里加入代码以下



<div id=KB1Parent>
	 <a onClick="expandIt('KB1');return false" href="#"><img src="plus.gif" border=0>精品下载</a>
</div>
<div class=child id=KB1Child>
		<a href="#"><img src="blank.gif" border=0>Dreamweaver 资源</a><br>
		<a href="#"><img src="blank.gif" border=0>Fireworks 资源</a><br>
		<a href="#"><img src="blank.gif" border=0>Flash 资源</a><br>
		<a href="#"><img src="blank.gif" border=0>Photoshop 资源</a>
</div>
<div  id=KB2Parent>
	 <a onClick="expandIt('KB2');return false" href="#"><img src="plus.gif" border=0>免费申请</a>
</div>
<div class=child id=KB2Child>
		<a href="#"><img src="blank.gif" border=0>免费计数器申请</a><br>
<a href="#"><img src="blank.gif" border=0>免费留言板申请</a><br>
		<a href="#"><img src="blank.gif" border=0>免费网上调查申请</a></div>
<div  id=KB3Parent>
	 <a onClick="expandIt('KB3');return false" href="#"><img src="plus.gif" border=0>酷站源码</a>
</div>
<div class=child id=KB3Child>
		<a href="#"><img src="blank.gif" border=0>脚本收集</a><br>
<a href="#"><img src="blank.gif" border=0>HTML特效</a><br>
		<a href="#"><img src="blank.gif" border=0>ASP源程序下载</a><br>
		<a href="#"><img src="blank.gif" border=0>XML方面</a><br>
</div>
<script>numTotal=3;scores[1]='KB1';scores[2]='KB2';scores[3]='KB3';</script>




制作要点:
  1、每一个分类都需定义值:
  <div id=KB1Parent>                       // ID值为唯一的
  <a onClick="expandIt('KB1'); return false" href="#" >精品下载</a></div>  // 定义onclick属性

--------------------------------------------------------------------------------
2、每一个分类下面的文件都需统一定义class及ID。
   <div class=child id=KB1Child>                  // ID值为唯一的
   <a href="#" >Dreamweaver 资源</div>
   <a href="#" >Dreamweaver 资源</div>
   </div>
--------------------------------------------------------------------------------
3、在分类的下边有一 script 的定义:
  <script>numTotal=3;scores[1]='KB1';scores[2]='KB2';scores[3]='KB3';</script>
  如果要增加一个类,则需把 numTotal 增加数值,再加一个scores[N]='KBN',例:
  <script>numTotal=4;scores[1]='KB1';scores[2]='KB2';scores[3]='KB3';scores[4]='KB4';</script>

论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics