一生能赌什么?

我在故我思 —— 哪里有梦想与希望

A-程序开发

用css和javascript做的树

这是个用css和javascript做的树,在IE6和Netscape7下做过测试。

分二个页面。tree.htm和subtree.htm

下面是代码:

tree.htm:

<!--
 树:以下为web下的树实现。原理:根据innerHTML属性从subtree.htm中取的子结点的数据,
 子结点数据取过来后保存到child属性下。
结点表示法:NodeX_X  第一个X表示第一层的序号为X,第二个X表示第二层序号为X。
 NodeX_:为子结点
 NodeX_Img:为结点的展开图标
 NodeX_Txt:为结点的文本
 存在的问题:在IE下结点之间存有一端距离。
 使用:在substree.htm中写从数据源中取的数据。
       点击结点要打开的窗口在selectNode(nodeId,url)中的url。
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
.tree {
 width: 200px;
 margin-top:0px;
}
.tree ul{
    margin-left:0px;
 text-align:left;
}
.tree ul ul{
 padding-left:10px;
}
.tree li{
 padding:0px 0 0 0;
 border:0px 0 0 0;
    list-style-type: none;
 width: 10em; 
}
.tree a {
 padding: 0px 0;
 text-decoration: none;
 color: #000;
 }

.tree a:hover {
  color: #faf5f8;
 background: #879186;
 }
.tree span{
 padding: 0px 0;
}
.selected{
 background: #879186;
}
.unselected{
 background:#FFFFFF;
}
-->
</style>
</head>
<script language="javascript" type="text/JavaScript">
<!--
function expandNode(parentNode,id,url){
 var node = document.getElementById(parentNode);
 if(node != null){
     var nodeChild = document.getElementById(parentNode+"_");
  var nodeImg = document.getElementById(parentNode+"_Img");
  if(node.expand!="yes"){
   if(node.loaded !="yes"){
    hiddenframe.location.replace("subtree.htm");
    node.loaded="yes";
    nodeChild.child="";
   }
   if(nodeChild != null){
    if(nodeChild.child !="");
      nodeChild.innerHTML=nodeChild.child;
      //nodeChild.style.visibility="visible";
     // nodeChild.style.height="auto";
   }
   if(nodeImg != null){
    nodeImg.src ="image/tree_minus.gif";
   }
   node.expand ="yes";
  }else{
                       var selectId = document.form1.selectId.value;
                       if(selectId.indexOf(parentNode)>-1){
                         selectNode(parentNode,"");  
                       }
                       //nodeChild.style.visibility="hidden";
                      // nodeChild.style.height="0px";
                       nodeChild.child=nodeChild.innerHTML;
                       nodeChild.innerHTML="";
         if(nodeImg !=null){
    nodeImg.src ="image/tree_plus.gif";
   }
   node.expand="no";
  }
  //alert("#"+nodeChild.innerHTML+"#");
 }

}
function selectNode(nodeId,url){
 var node = document.getElementById(nodeId+"_Txt");
 if(node != null){
  var selectNode =document.getElementById(document.form1.selectId.value+"_Txt");
  if(selectNode != null){
   selectNode.className="unselected";
  }
  node.className="selected";
  document.form1.selectId.value=nodeId;
 }

}
-->
</script>
<body>

<div class="tree">
<ul>
      <li id="Node0"><a href="javascript:expandNode('Node0',0,'')"><img id ="Node0_Img" src="image/tree_plus.gif" border="0" /></a><span id="Node0_Txt"><a  href="javascript:selectNode('Node0','url')">系统</a></span> </li>
   <ul id="Node0_"></ul>
</ul>
</div>
<iframe width="100%" height="0"  name="hiddenframe"></iframe>
<form name="form1">
<input name="selectId"  type="hidden" value="dd">
</form>
</body>
</html>

subtree.htm:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<script language="javascript" type="text/JavaScript">
<!--
var x =parent.document.getElementById("Node0_");
if(x != null){
x.innerHTML="<li id=\"Node0_0\"><a href=\"javascript:expandNode('Node0_0',1,'')\"><img id=\"Node0_0_Img\" src=\"image/tree_plus.gif\" border=\"0\" /></a><span id=\"Node0_0_Txt\"><a href=\"javascript:selectNode('Node0_0','')\">应用系统</a>< /span></li><ul id=\"Node0_0_\"></ul><li id=\"Node0_1\"><a href=\"javascript:expandNode('Node0_1',2,'')\"><img id=\"Node0_1_Img\" src=\"image/tree_plus.gif\" border=\"0\" /></a><span id=\"Node0_1_Txt\"><a href=\"javascript:selectNode('Node0_1','')\">基础信息</a>< /span></li><ul id=\"Node0_1_\"></ul><li id=\"Node0_2\"><a href=\"javascript:expandNode('Node0_2',3,'')\"><img id=\"Node0_2_Img\" src=\"image/tree_plus.gif\" border=\"0\" /></a><span id=\"Node0_2_Txt\"><a href=\"javascript:selectNode('Node0_2','')\">计划管理</a>< /span></li><ul id=\"Node0_2_\"></ul><li id=\"Node0_3\"><a href=\"javascript:expandNode('Node0_3',4,'')\"><img id=\"Node0_3_Img\" src=\"image/tree_plus.gif\" border=\"0\" /></a><span id=\"Node0_3_Txt\"><a href=\"javascript:selectNode('Node0_3','')\">设备维护</a>< /span></li><ul id=\"Node0_3_\"></ul><li id=\"Node0_4\"><a href=\"javascript:expandNode('Node0_4',5.'')\"><img id=\"Node0_4_Img\" src=\"image/tree_plus.gif\" border=\"0\" /></a><span id=\"Node0_4_Txt\"><a href=\"javascript:selectNode('Node0_4','')\">变电运行</a>< /span></li><ul id=\"Node0_4_\"></ul><li id=\"Node0_5\"><a href=\"javascript:expandNode('Node0_5',6,'')\"><img id=\"Node0_5_Img\" src=\"image/tree_plus.gif\" border=\"0\" /></a><span id=\"Node0_5_Txt\"><a href=\"javascript:selectNode('Node0_5','')\">物资</a>< /span></li><ul id=\"Node0_5_\"></ul><li id=\"Node0_6\"><a href=\"javascript:expandNode('Node0_6',7,'')\"><img id=\"Node0_6_Img\" src=\"image/tree_plus.gif\" border=\"0\" /></a><span id=\"Node0_6_Txt\"><a href=\"javascript:selectNode('Node0_6','')\">工程</a>< /span></li><ul id=\"Node0_6_\"></ul><li id=\"Node0_7\"><a href=\"javascript:expandNode('Node0_7',8,'')\"><img id=\"Node0_7_Img\" src=\"image/tree_plus.gif\" border=\"0\" /></a><span id=\"Node0_7_Txt\"><a href=\"javascript:selectNode('Node0_7','')\">调度</a>< /span></li><ul id=\"Node0_7_\"></ul><li id=\"Node0_8\"><a href=\"javascript:expandNode('Node0_8',9.'')\"><img id=\"Node0_8_Img\" src=\"image/tree_plus.gif\" border=\"0\" /></a><span id=\"Node0_8_Txt\"><a href=\"javascript:selectNode('Node0_8','')\">安监</a>< /span></li><ul id=\"Node0_8_\"></ul><li id=\"Node0_9\"><a href=\"javascript:expandNode('Node0_9',10,'')\"><img id=\"Node0_9_Img\" src=\"image/tree_plus.gif\" border=\"0\" /></a><span id=\"Node0_9_Txt\"><a href=\"javascript:selectNode('Node0_9','')\">输配电运行</a>< /span></li><ul id=\"Node0_9_\"></ul>";
}
-->
</script>
</body>
</html>

发表于 @ 2005年03月04日 2:55 PM | 评论 (0)

一个小的WEB项目中的实现方法讨论

    摘要:一个小的WEB项目中的实现方法讨论    (全文共3694字)——点击此处阅读全文

发表于 @ 2004年12月17日 6:36 PM | 评论 (0)

网页色彩设计点滴

    摘要:网页色彩设计点滴    (全文共5389字)——点击此处阅读全文

发表于 @ 2004年12月15日 11:25 AM | 评论 (0)

网络最经典命令行

    摘要:网络最经典命令行    (全文共5613字)——点击此处阅读全文

发表于 @ 2004年12月07日 10:00 AM | 评论 (0)

在Eclipse中使用Ant

    摘要:在Eclipse中使用Ant    (全文共10165字)——点击此处阅读全文

发表于 @ 2004年11月25日 9:49 AM | 评论 (0)

eclipse启动参数研究 选择自 china2wto 的 Blog

    摘要:eclipse启动参数研究 选择自 china2wto 的 Blog     (全文共1451字)——点击此处阅读全文

发表于 @ 2004年11月25日 9:35 AM | 评论 (2)

JSP分页技术

    摘要: 在使用数据库的过程中,不可避免的需要使用到分页的功能,可是JDBC的规范对此却没有很好的解决。对于这个需求很多朋友都有自己的解决方案,比如使用Vector等集合类先保存取出的数据再分页。但这种方法的可用性很差,与JDBC本身的接口完全不同,对不同类型的字段的支持也不好。这里提供了一种与JDBC兼容性非常好的方案。     (全文共12236字)——点击此处阅读全文

发表于 @ 2004年11月02日 8:42 AM | 评论 (1)

订阅某用户的donews blog最新更新。

    摘要:订阅某用户的donews blog最新更新。    (全文共742字)——点击此处阅读全文

发表于 @ 2004年10月14日 6:22 PM | 评论 (0)

Struts用户指南

    摘要:Struts用户指南    (全文共29265字)——点击此处阅读全文

发表于 @ 2004年08月19日 9:45 AM | 评论 (0)

项目管理的20条锦囊妙计

    摘要:项目管理的20条锦囊妙计    (全文共3474字)——点击此处阅读全文

发表于 @ 2004年07月13日 4:27 PM | 评论 (0)

第1页,共2页

news

google 本站

last posts