简单javascript树

<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
 
<script type="text/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(".ballchild {display:none}")
        }
        write("</STYLE>");
    }
}
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");  //divColl:数组
        for (i=0; i<divColl.length; i++) {
            whichEl = divColl(i);  //单个得div
            //whichEl = CD1Child.display:none
           
            if (whichEl.className == "ballchild") whichEl.style.display = "none";
        }
    }
}
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 expandIt(el,img) {
    if (!ver4) return;
    if (IE4) {
        whichEl = eval(el + "Child");
        if (whichEl.style.display == "none") {
            whichEl.style.display = "block";
            img.src="images/open.gif";
        }else {
            whichEl.style.display = "none";
            img.src="images/closed.gif";
        }
    }else {
        whichEl = eval("document." + el + "Child");
        if (whichEl.visibility == "hide") {
            whichEl.visibility = "show";
            img.src="images/open.gif";
        }
        else {
            whichEl.visibility = "hide";
            img.src="images/closed.gif";
        }

        arrange();
    }
}
  </script>

 
 
    </head>

 
 
<body onload="initIt()">
     <div id="CD1parent" class="ballparent">
      <a href="tree.jsp" onClick="expandIt('CD1',img1); return false">
      <img id="img1" src='images/closed.gif' width='18' height='16' align='absmiddle' border=0>
      运动系类
     </div>
    
     <div id="CD1Child" class="ballchild">
         球类<br>
         跑步类<br>
         游泳类
     </div>
      <div id="CD2parent" class="ballparent">
      <a href="tree.jsp" onClick="expandIt('CD2',img1); return false">
      <img id="img1" src='images/closed.gif' width='18' height='16' align='absmiddle' border=0>
      生活用品类
     </div>
     <div id="CD2Child" class="ballchild">
         牙刷<br>
         笔<br>
         铅笔
     </div>
  </body>
</html>

你可能感兴趣的:(JavaScript,html,function,Class,div,border)