脚本有点看不懂,咋办?

<script language=javascript>
if(NS4){
firstEl="KB1Parent";
firstInd=getIndex(firstEl);
arrange();
}

绝地无双
浏览 271回答 2
2回答

大话西游666

这个 页面上的其他地方 肯定对NS4 firstEI firstIndArrange()进行了定义的。光看这里 神仙也看不明白!

饮歌长啸

-----以下是完整代码和解释----NS4 = (document.layers) ? 1 : 0;IE4 = (document.all) ? 1 : 0;&nbsp;ver4 = (NS4 || IE4) ? 1 : 0;声明几个变量。当用户的浏览器是IE时,变量IE4的值为1,当用户的浏览器是Netscape时,变量NS4的值为1,当用户的浏览器是IE或是Netscape时,变量ver4的值为1。&nbsp;if (ver4){ with (document)&nbsp;{write("<STYLE TYPE='text/css'>");if (NS4) {write(".parent{position:absolute; visibility:visible}");&nbsp;write(".child {position:absolute; visibility:visible}");&nbsp;write(".regular {position:absolute; visibility:visible}") }&nbsp;else { write(".child {display:none}") }&nbsp;write("</STYLE>");} }&nbsp;这段代码相当于一个样式,定义各个层的位置及显示状态。&nbsp;function getIndex(el){ ind = null;&nbsp;for (i=0; i<document.layers.length; i++)&nbsp;{ whichEl = document.layers[i];&nbsp;if (whichEl.id == el)&nbsp;{ ind = i; break; } }&nbsp;return ind; }&nbsp;定义一个函数getIndex,功能是获得变量ind的值。&nbsp;function arrange()&nbsp;{ nextY = document.layers[firstInd].pageY +document.layers[firstInd].document.height;for (i=firstInd+1; i<document.layers.length; i++)&nbsp;{ whichEl = document.layers[i];&nbsp;if (whichEl.visibility != "hide")&nbsp;{ whichEl.pageY = nextY; nextY += whichEl.document.height; } } }&nbsp;定义一个函数arrange(),功能就是定义一下页面上元素的位置。当菜单打开时,页面上菜单以下的东西的位置顺序往下推,菜单合起时,菜单以下的东西自动上移。&nbsp;function initIt(){ if (!ver4) return;&nbsp;if (NS4) { for (i=0; i<document.layers.length; i++)&nbsp;{ whichEl = document.layers[i];&nbsp;if (whichEl.id.indexOf("Child") != -1) whichEl.visibility = "hide"; }&nbsp;arrange(); }&nbsp;else { divColl = document.all.tags("DIV");for (i=0; i<divColl.length; i++)&nbsp;{ whichEl = divColl(i);if (whichEl.className == "child")&nbsp;whichEl.style.display = "none"; } } }&nbsp;定义函数initIt(),页面载入时,首先调用该函数。功能是初始化菜单,让页面载入时,菜单处于未打开状态。&nbsp;function expandIt(el) {&nbsp;if (!ver4) return;&nbsp;if (IE4) { whichEl = eval(el + "Child");if (whichEl.style.display == "none") { whichEl.style.display = "block"; }&nbsp;else { whichEl.style.display = "none"; } }&nbsp;else { whichEl = eval("document." + el + "Child");&nbsp;if (whichEl.visibility == "hide")&nbsp;{ whichEl.visibility = "show"; }else { whichEl.visibility = "hide"; } arrange(); } }&nbsp;onload = initIt;&nbsp;定义一个函数expandIt(el)。由于层的可见状态在IE浏览器和NetScape浏览器中的解释是不同的,所以要分别讨论,判断菜单的状态。如果菜单是打开的,那么当再点击时,子菜单就不可见;如果菜单是关闭状态,那么当再点击时,子菜单就可见。&nbsp;<div id="KB1Parent" class="parent"><a href="#" onClick="expandIt('KB1'); return false" ><img src="img/plus.gif" border=0>文件夹一</a></div>。。。<a href="sample.htm" target="_blank" ><img src="img/spacer.gif" border=0 alt=""><img src="img/open.gif" border=0>页面三</a>&nbsp;这一部分是页面上所显示的部分,包括那些形象的小“文件夹”图标,和文字。&nbsp;<script language="JavaScript">if(NS4){ firstEl = "KB1Parent";&nbsp;firstInd = getIndex(firstEl);&nbsp;arrange(); }&nbsp;</script>&nbsp;如果用户的浏览器是NetScape,先初始化一下变量。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript