这个树型菜单的代码简单一点。
<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="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>