简单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 οnlοad="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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值