我搜集过一段类似的js,不知道有用否

来源:岁月联盟 编辑:zhuzhu 时间:2003-07-11
脚本说明:
第一步:把如下代码加入<head>区域中
<SCRIPT LANGUAGE="JavaScript">
<!--
var bV=parseInt(navigator.appVersion);
var NS4=(document.layers) ? true : false;
var IE4=((document.all)&&(bV>=4))?true:false;
var ver4 = (NS4 || IE4) ? true : false;

function expandIt(){return}
function expandAll(){return}
function nomsg(){self.status="";}

if(ver4){
  document.write("<SCR"+"IPT LANGUAGE=/"JavaScript/" SRC=/"rsmenu.js/"></SCR"+"I
PT>");
}
//-->
</SCRIPT>

第二步:把如下代码加入<body>区域中
<span class="label"></span><br>
<!---------- begin OUTLINE ----------->
<!--上方全部展开/关闭-->
<A HREF="#" onClick="expandAll(false); return false"><IMG NAME="imEx" SRC="bulle
t-plus.gif" WIDTH=9 HEIGHT=9 BORDER=0 ALT="展开或关闭全部菜单"><FONT STYLE="font-
size: 9pt">展开/关闭全部</FONT></A>
<!-- <BLOCKQUOTE> -->

<!--第一级父菜单-->
<DIV ID="elOneParent" CLASS=parent style="margin-left: 0.1px">
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 WIDTH=101><tr><td class=label>
<A HREF="#" style="color:#FFFF00; text-decoration:none;"  onClick="expandIt('elO
ne'); return false"><IMG NAME="imEx" SRC="bullet-plus.gif" WIDTH=9 HEIGHT=9 BORDE
R=0 ALT="展开全部菜单"> 主菜单一
</a></td></tr></table>
</DIV>
<!--第一级子菜单-->
<DIV ID="elOneChild" CLASS=child style="margin-left: 0.5px">
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 WIDTH=96>
<tr><td>
        <A HREF="1.htm" target="data">连接页面1</A><BR>
</td></tr><tr><td>
        <A HREF="2.htm" target="data">连接页面2</A><BR>
</td></tr><tr><td>
    <A HREF="3.htm" target="data">连接页面3</A><BR>
</td></tr><tr>
      <td height="12"> <A HREF="4.htm" target="data">连接页面4</A> </td>
    </tr></table>
</DIV>

<!--第二级父菜单-->
<DIV ID="elTwoParent" CLASS=parent style="margin-left: 0.1px">
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 WIDTH=101><tr><td class=label>
<A HREF="#" style="color:#FFFF00; text-decoration:none;"  onClick="expandIt('elT
wo'); return false"><IMG NAME="imEx" SRC="bullet-plus.gif" WIDTH=9 HEIGHT=9 BORDE
R=0 ALT="展开全部菜单"> 主菜单二
</a></td></tr></table>
</DIV>

<!--第二级子菜单-->
<DIV ID="elTwoChild" CLASS=child style="margin-left: 0.5px">
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 WIDTH=96>
<tr><td>
        <A HREF="1.htm" target="data">连接页面1</A><BR>
</td></tr><tr><td>
        <A HREF="2.htm" target="data">连接页面2</A><BR>
</td></tr><tr><td>
    <A HREF="3.htm" target="data">连接页面3</A><BR>
</td></tr><tr><td>
    <A HREF="4.htm" target="data">连接页面4</A>
</td></tr></table>
</DIV>

<!--第三级父菜单-->
<DIV ID="elThreeParent" CLASS=parent style="margin-left: 0.1px">
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 WIDTH=101><tr><td class=label>
<A HREF="#" style="color:#FFFF00; text-decoration:none;"  onClick="expandIt('elT
hree'); return false"><IMG NAME="imEx" SRC="bullet-plus.gif" WIDTH=9 HEIGHT=9 BOR
DER=0 ALT="展开全部菜单"> 主菜单三
</a></td></tr></table>
</DIV>

<!--第三级子菜单-->
<DIV ID="elThreeChild" CLASS=child style="margin-left: 0.5px">
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 WIDTH=96>
<tr><td>
        <A HREF="1.htm" target="data">连接页面1</A><BR>
</td></tr><tr><td>
        <A HREF="2.htm" target="data">连接页面2</A><BR>
</td></tr><tr><td>
    <A HREF="3.htm" target="data">连接页面3</A><BR>
</td></tr><tr><td>
    <A HREF="4.htm" target="data">连接页面4</A>
</td></tr></table>
</DIV>

<!--第四级父菜单-->
<DIV ID="elFourParent" CLASS=parent style="margin-left: 0.1px">
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 WIDTH=101><tr><td class=label>
<A HREF="#" style="color:#FFFF00; text-decoration:none;"  onClick="expandIt('elF
our'); return false"><IMG NAME="imEx" SRC="bullet-plus.gif" WIDTH=9 HEIGHT=9 BORD
ER=0 ALT="展开全部菜单"> 主菜单四
</a></td></tr></table>
</DIV>

<!--第四级子菜单-->
<DIV ID="elFourChild" CLASS=child style="margin-left: 0.5px">
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 WIDTH=96>
<tr><td>
        <A HREF="1.htm" target="data">连接页面1</A><BR>
</td></tr><tr><td>
        <A HREF="2.htm" target="data">连接页面2</A><BR>
</td></tr><tr><td>
    <A HREF="3.htm" target="data">连接页面3</A><BR>
</td></tr><tr><td>
    <A HREF="4.htm" target="data">连接页面4</A>
</td></tr></table>
</DIV>

<!--第五级父菜单-->
<DIV ID="elFiveParent" CLASS=parent style="margin-left: 0.1px">
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 WIDTH=101><tr><td class=label>
<A HREF="#" style="color:#FFFF00; text-decoration:none;"  onClick="expandIt('elF
ive'); return false"><IMG NAME="imEx" SRC="bullet-plus.gif" WIDTH=9 HEIGHT=9 BORD
ER=0 ALT="展开全部菜单"> 主菜单五
</a></td></tr></table>
</DIV>

<!--第五级子菜单-->
<DIV ID="elFiveChild" CLASS=child style="margin-left: 0.5px">
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 WIDTH=96>
<tr><td>
        <A HREF="1.htm" target="data">连接页面1</A><BR>
</td></tr><tr><td>
        <A HREF="2.htm" target="data">连接页面2</A><BR>
</td></tr><tr><td>
    <A HREF="3.htm" target="data">连接页面3</A><BR>
</td></tr><tr><td>
    <A HREF="4.htm" target="data">连接页面4</A>
</td></tr></table>
</DIV>

<!--第六级父菜单-->
<DIV ID="elSixParent" CLASS=parent style="margin-left: 0.1px">
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 WIDTH=101><tr><td class=label>
<A HREF="#" style="color:#FFFF00; text-decoration:none;"  onClick="expandIt('elS
ix'); return false"><IMG NAME="imEx" SRC="bullet-plus.gif" WIDTH=9 HEIGHT=9 BORDE
R=0 ALT="展开全部菜单"> 主菜单六
</a></td></tr></table>
</DIV>

<!--第六级子菜单-->
<DIV ID="elSixChild" CLASS=child style="margin-left: 0.5px">
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 WIDTH=96>
<tr><td>
        <A HREF="1.htm" target="data">连接页面1</A><BR>
</td></tr><tr><td>
        <A HREF="2.htm" target="data">连接页面2</A><BR>
</td></tr><tr><td>
    <A HREF="3.htm" target="data">连接页面3</A><BR>
</td></tr><tr><td>
    <A HREF="4.htm" target="data">连接页面4</A>
</td></tr></table>
</DIV>

<!-- </BLOCKQUOTE> -->
<!--下方全部展开/关闭-->
<DIV ID="elExpParent" CLASS=regular> <A HREF="#" onClick="expandAll(true); retur
n false"><IMG NAME="imEx" SRC="bullet-plus.gif" WIDTH=9 HEIGHT=9 BORDER=0 ALT="展
开/关闭全部">展开/关闭全部</A> </DIV>

<!---------- end OUTLINE ----------->

<br>

<SCRIPT LANGUAGE="JavaScript1.2">
<!--
if(NS4){
  firstEl = "elOneParent";
  firstInd = getIndex(firstEl);
  showAll();
  arrange();
}
//-->
</SCRIPT>

rsment.js
isExpanded = false;

function getIndex(el) {
   ind = null;
   for (i=0; i<document.layers.length; i++) {
    whichEl = 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 (NS4) {
    for (i=0; i<document.layers.length; i++) {
       whichEl = document.layers[i];
        if (whichEl.id.indexOf("Child") != -1) whichEl.visibility = "hide";
    }
    arrange();
   }
   else {
    tempColl = document.all.tags("DIV");
    for (i=0; i<tempColl.length; i++) {
       if (tempColl(i).className == "child") tempColl(i).style.display = "none";
    }
   }
}

function expandIt(el) {
   if (!ver4) return;
   if (IE4) {expandIE(el)} else {expandNS(el)}
}

function expandIE(el) {
   whichEl = eval(el + "Child");
   whichIm = event.srcElement;

   if (whichEl.style.display == "none") {
    whichEl.style.display = "block";
    whichIm.src = "bullet-minus.gif";        
   }
   else {
    whichEl.style.display = "none";
    whichIm.src = "bullet-plus.gif";
   }
}

function expandNS(el) {
   whichEl = eval("document." + el + "Child");
   whichIm = eval("document." + el + "Parent.document.images['imEx']");
   if (whichEl.visibility == "hide") {
    whichEl.visibility = "show";
    whichIm.src = "bullet-minus.gif";
   }
   else {
    whichEl.visibility = "hide";
    whichIm.src = "bullet-plus.gif";
   }
   arrange();
}

function showAll() {
   for (i=firstInd; i<document.layers.length; i++) {
    whichEl = document.layers[i];
    whichEl.visibility = "show";
   }
}

function expandAll(isBot) {
   newSrc = (isExpanded) ? "bullet-plus.gif" : "bullet-minus.gif";

   if (NS4) {
        document.images["imEx"].src = newSrc;
    for (i=firstInd; i<document.layers.length; i++) {
        whichEl = document.layers[i];
        if (whichEl.id.indexOf("Parent") != -1) {
           whichEl.document.images["imEx"].src = newSrc;
        }
        if (whichEl.id.indexOf("Child") != -1) {
           whichEl.visibility = (isExpanded) ? "hide" : "show";
        }
    }

    arrange();
    if (isBot && isExpanded) scrollTo(0,document.layers[firstInd].pageY);
   }
   else {
    divColl = document.all.tags("DIV");
    for (i=0; i<divColl.length; i++) {
        if (divColl(i).className == "child") {
           divColl(i).style.display = (isExpanded) ? "none" : "block";
        }
    }
    imColl = document.images.item("imEx");
    for (i=0; i<imColl.length; i++) {
        imColl(i).src = newSrc;
    }
   }

   isExpanded = !isExpanded;
}

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

onload = initIt;