盾怪网教程:是一个免费提供流行杀毒软件教程、在线学习分享的学习平台!

树型菜单-用JS编写

时间:2024/11/23作者:未知来源:盾怪网教程人气:

[摘要]这个树型菜单的代码简单一点。 <script language="JavaScript"> NS4 = (document.layers) ? 1 : 0; IE4 ...

这个树型菜单的代码简单一点。
<script language="JavaScript">
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++) {
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 (!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="http://www.okasp.com/techinfo/img/plus.gif" border=0>文件夹一</a></div>
<div id="KB1Child" class="child"><a href="sample.htm" target="_blank" ><img

src="http://www.okasp.com/techinfo/img/spacer.gif" border=0 alt='树型菜单-用JS编写'><img src="http://www.okasp.com/techinfo/img/open.gif" border=0>页面一</a><br>
<a href="sample.htm" target="_blank" ><img src="http://www.okasp.com/techinfo/img/spacer.gif" border=0 alt='树型菜单-用JS编写' width="15"

height="11"><img src="http://www.okasp.com/techinfo/img/open.gif" border=0>页面二</a><br>
<a href="sample.htm" target="_blank" ><img src="http://www.okasp.com/techinfo/img/spacer.gif" border=0 alt='树型菜单-用JS编写' width="15"

height="11"><img src="http://www.okasp.com/techinfo/img/open.gif" border=0>页面三</a></div>
<div id="KB2Parent" class="parent"><a href="#" onClick="expandIt('KB2'); return false" ><img

src="http://www.okasp.com/techinfo/img/plus.gif" border=0>文件夹二</a></div>
<div id="KB2Child" class="child"><a href="sample.htm" target="_blank" ><img

src="http://www.okasp.com/techinfo/img/spacer.gif" border=0 alt='树型菜单-用JS编写' width="15" height="11"><img src="http://www.okasp.com/techinfo/img/open.gif" border=0>页面一</a><br>
<a href="sample.htm" target="_blank" ><img src="http://www.okasp.com/techinfo/img/spacer.gif" border=0 alt='树型菜单-用JS编写'><img

src="http://www.okasp.com/techinfo/img/open.gif" border=0>页面二</a><br>
<a href="sample.htm" target="_blank" ><img src="http://www.okasp.com/techinfo/img/spacer.gif" border=0 alt='树型菜单-用JS编写' width="15"

height="11"><img src="http://www.okasp.com/techinfo/img/open.gif" border=0>页面三</a></div>
<div id="KB3Parent" class="parent"><a href="#" onClick="expandIt('KB3'); return false" ><img

src="http://www.okasp.com/techinfo/img/plus.gif" border=0>文件夹三</a></div>
<div id="KB3Child" class="child"> <a href="sample.htm" target="_blank" ><img

src="http://www.okasp.com/techinfo/img/spacer.gif" border=0 alt='树型菜单-用JS编写'><img src="http://www.okasp.com/techinfo/img/open.gif" border=0>页面一</a><br>
<a href="sample.htm" target="_blank" ><img src="http://www.okasp.com/techinfo/img/open.gif" border=0>页面二</a><br>
<a href="sample.htm" target="_blank" ><img src="http://www.okasp.com/techinfo/img/spacer.gif" border=0 alt='树型菜单-用JS编写'><img

src="http://www.okasp.com/techinfo/img/open.gif" border=0>页面三</a></div>
<script language="JavaScript">
if (NS4) {
firstEl = "KB1Parent";
firstInd = getIndex(firstEl);
arrange();
}
</script>

关键词:树型菜单-用JS编写




Copyright © 2012-2018 盾怪网教程(http://www.dunguai.com) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版