📄 menutree.htm
字号:
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) {
whichEl = eval(el + "Child");
if (whichEl.style.display == "none") {
whichEl.style.display = "block";
}
else {
whichEl.style.display = "none";
}
}
else {
whichEl = eval("document." + el + "Child");
if (whichEl.visibility == "hide") {
whichEl.visibility = "show";
}
else {
whichEl.visibility = "hide";
}
arrange();
}
}
onload = initIt;
</script>
</font></p>
<div id="KB1Parent" class="parent"> <a href="#" onClick="expandIt('KB1'); return false" ><img src="img/plus.gif" border=0>文件夹一</a></div>
<div id="KB1Child" class="child"> <a href="sample.htm" target="_blank" ><img src="img/spacer.gif" border=0 alt=""><img src="img/open.gif" border=0>页面一</a><br>
<a href="sample.htm" target="_blank" ><img src="img/spacer.gif" border=0 alt="" width="15" height="11"><img src="img/open.gif" border=0>页面二</a><br>
<a href="sample.htm" target="_blank" ><img src="img/spacer.gif" border=0 alt="" width="15" height="11"><img src="img/open.gif" border=0>页面三</a></div>
<div id="KB2Parent" class="parent"> <a href="#" onClick="expandIt('KB2'); return false" ><img src="img/plus.gif" border=0>文件夹二</a></div>
<div id="KB2Child" class="child"> <a href="sample.htm" target="_blank" ><img src="img/spacer.gif" border=0 alt="" width="15" height="11"><img src="img/open.gif" border=0>页面一</a><br>
<a href="sample.htm" target="_blank" ><img src="img/spacer.gif" border=0 alt=""><img src="img/open.gif" border=0>页面二</a><br>
<a href="sample.htm" target="_blank" ><img src="img/spacer.gif" border=0 alt="" width="15" height="11"><img src="img/open.gif" border=0>页面三</a></div>
<div id="KB3Parent" class="parent"> <a href="#" onClick="expandIt('KB3'); return false" ><img src="img/plus.gif" border=0>文件夹三</a></div>
<div id="KB3Child" class="child"> <a href="sample.htm" target="_blank" ><img src="img/spacer.gif" border=0 alt=""><img src="img/open.gif" border=0>页面一</a><br>
<a href="sample.htm" target="_blank" ><img src="img/open.gif" border=0>页面二</a><br>
<a href="sample.htm" target="_blank" ><img src="img/spacer.gif" border=0 alt=""><img src="img/open.gif" border=0>页面三</a></div>
<script language="JavaScript">
if (NS4) {
firstEl = "KB1Parent";
firstInd = getIndex(firstEl);
arrange();
}
</script></textarea>
</p>
</form>
<b> </b></td>
<td bgcolor="5F74BF" width="28" align="center"> </td>
<td width="37" align="center"> </td>
</tr>
<tr>
<td align="center" valign="bottom">
<table width="238" border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<td>
<table width="110" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="5F74BF" align="center">
<td class="p1" align="right"><b><font color="#FFFFFF">源程序讲解:</font></b></td>
<td class="p1" width="11"><img src="img/bule2.gif" width="11" height="18"></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td width="457" class="p2" valign="top"> </td>
<td bgcolor="5F74BF" width="28" align="center"><img src="img/bule1.gif" width="28" height="49"></td>
<td width="37" align="center"> </td>
</tr>
</table>
<table width="760" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td class="p2" align="right" width="693"> <br>
<table width="650" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="25">
<table width="100%" border="1" cellspacing="1" cellpadding="1" bordercolorlight="#666666" bordercolordark="#666666" class=p2>
<tr class=p2>
<td width="50%"><font color="#000000">NS4 = (document.layers)
? 1 : 0;<br>
IE4 = (document.all) ? 1 : 0; <br>
ver4 = (NS4 || IE4) ? 1 : 0;<br>
</font></td>
<td width="50%" class=p2>声明几个变量。当用户的浏览器是IE时,变量IE4的值为1,当用户的浏览器是Netscape时,变量NS4的值为1,当用户的浏览器是IE或是Netscape时,变量ver4的值为1。</td>
</tr>
<tr bgcolor="CFDFFF">
<td width="50%">if (ver4)<br>
{ with (document) <br>
{write("<STYLE TYPE='text/css'>");<br>
if (NS4) {<br>
write(".parent{position:absolute; visibility:visible}");
<br>
write(".child {position:absolute; visibility:visible}");
<br>
write(".regular {position:absolute; visibility:visible}")
} <br>
else { write(".child {display:none}") } <br>
write("</STYLE>");<br>
} }</td>
<td width="50%">这段代码相当于一个样式,定义各个层的位置及显示状态。</td>
</tr>
<tr>
<td width="50%">function getIndex(el)<br>
{ ind = null; <br>
for (i=0; i<document.layers.length; i++) <br>
{ whichEl = document.layers[i]; <br>
if (whichEl.id == el) <br>
{ ind = i; break; } } <br>
return ind; }</td>
<td width="50%">定义一个函数getIndex,功能是获得变量ind的值。</td>
</tr>
<tr bgcolor="CFDFFF">
<td width="50%">function arrange() <br>
{ nextY = document.layers[firstInd].pageY +document.layers[firstInd].document.height;<br>
for (i=firstInd+1; i<document.layers.length; i++) <br>
{ whichEl = document.layers[i]; <br>
if (whichEl.visibility != "hide") <br>
{ whichEl.pageY = nextY; nextY += whichEl.document.height; }
} }</td>
<td width="50%">定义一个函数arrange(),功能就是定义一下页面上元素的位置。当菜单打开时,页面上菜单以下的东西的位置顺序往下推,菜单合起时,菜单以下的东西自动上移。</td>
</tr>
<tr>
<td width="50%">function initIt()<br>
{ if (!ver4) return; <br>
if (NS4) { for (i=0; i<document.layers.length; i++) <br>
{ whichEl = document.layers[i]; <br>
if (whichEl.id.indexOf("Child") != -1) whichEl.visibility
= "hide"; } <br>
arrange(); } <br>
else { divColl = document.all.tags("DIV");<br>
for (i=0; i<divColl.length; i++) <br>
{ whichEl = divColl(i);<br>
if (whichEl.className == "child") <br>
whichEl.style.display = "none"; } } }</td>
<td width="50%">定义函数initIt(),页面载入时,首先调用该函数。功能是初始化菜单,让页面载入时,菜单处于未打开状态。</td>
</tr>
<tr bgcolor="CFDFFF">
<td rowspan="3">function expandIt(el) { <br>
if (!ver4) return; <br>
if (IE4) { whichEl = eval(el + "Child");<br>
if (whichEl.style.display == "none") { whichEl.style.display
= "block"; } <br>
else { whichEl.style.display = "none"; } } <br>
else { whichEl = eval("document." + el + "Child");
<br>
if (whichEl.visibility == "hide") <br>
{ whichEl.visibility = "show"; }<br>
else { whichEl.visibility = "hide"; } arrange(); }
} <br>
onload = initIt;</td>
<td rowspan="3">定义一个函数expandIt(el)。由于层的可见状态在IE浏览器和NetScape浏览器中的解释是不同的,所以要分别讨论,判断菜单的状态。如果菜单是打开的,那么当再点击时,子菜单就不可见;如果菜单是关闭状态,那么当再点击时,子菜单就可见。</td>
</tr>
<tr> </tr>
<tr> </tr>
<tr>
<td width="50%">
<p><div id="KB1Parent" class="parent"><br>
<a href="#" onClick="expandIt('KB1'); return
false" ><br>
<img src="img/plus.gif" border=0>文件夹一</a></div><br>
。。。<br>
<a href="sample.htm" target="_blank"
><img src="img/spacer.gif" border=0 alt=""><img
src="img/open.gif" border=0>页面三</a> </p>
</td>
<td width="50%">这一部分是页面上所显示的部分,包括那些形象的小“文件夹”图标,和文字。</td>
</tr>
<tr bgcolor="CFDFFF">
<td width="50%"><script language="JavaScript"><br>
if(NS4){ firstEl = "KB1Parent"; <br>
firstInd = getIndex(firstEl); <br>
arrange(); } <br>
</script></td>
<td width="50%">如果用户的浏览器是NetScape,先初始化一下变量。</td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<br>
</td>
<td class="p2" width="18"> </td>
<td class="p2" width="1" bgcolor="A8A8AB"><img src="img/blank.gif" width="1" height="1"></td>
<td class="p2" width="48"> </td>
</tr>
</table>
<table width="760" border="0" cellspacing="0" cellpadding="0" align="center">
<tr bgcolor="5F74BF">
<td> </td>
</tr>
</table>
<!--底部开始-->
<!--底部结束--> <p></p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -