动态载入asp树源码

时间:2007-09-06 19:34:00 

一个动态载入asp树源码。把 node.htc, style.css 保存与 css 目录下. index.asp subtree.asp 放与根目录.
另新建一ACCESS数据库 tree.mdb
表deeptree 结构为 id,content, parentid,link

页面: index.asp


<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%> 
<%Option Explicit%> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<title>tree</title> 
<link href="css/style.css" rel="stylesheet" type="text/css"> 
<script language="JavaScript"> 
<!-- 
var d1,d2; 
function expand(id) 

 var d=new Date(); 
 d1=d.valueOf(); 
 var s_id = eval("s" + id); 
 var dir_id = eval("dir" + id); 
 if(s_id.href != ’’) 
 { 
  //window.open(s_id.href); 
  //or 
  //top.frames[’FrameName’].location.href = s_id.href; 
 } 
 switch(dir_id.open) 
 { 
  //改变"+","-" 
  case "true": 
  { 
   with(dir_id) 
   { 
    innerText = "+"; 
    open = "false"; 
    className = ’dirclose’; 
   } 
   if(document.getElementById("t" + id)) 
   { 
    eval("t"+id).style.display = ’none’; 
    document.getElementById("load_" + id).style.display = ’none’; 
    return; 
   } 
   else 
   { 
    document.getElementById("load_" + id).style.display = ’none’; 
   } 
   break; 
  } 
  case "false": 
  { 
   with(dir_id) 
   { 
    innerText = "-"; 
    open = "true"; 
    className = ’diropen’; 
   } 
    
   document.getElementById("load_" + id).style.display = ’’; 
    
   if(document.getElementById("t" + id)) 
   { 
    eval("t" + id).style.display = ’’; 
    eval("load_" + id).style.display = ’none’; 
    return; 
   } 
      else  
   { 
    document.frames[’hifm’].location.replace("subtree.asp?id=" + id); 
   } 
      break; 
  } 
  default:dir_id.innerText = "."; dir_id.className = ’dirNode’; return; 
 } 

function ArrToHtml(ArrNode,nodeid) 

 //输出到页面 
 var node_html = ’<table id="t’ + nodeid + ’" width="100%" border="0" style="position: relative; left: 18px;" cellspacing="0" cellpadding="0">’; 
 var str,opened,cls 
 for (var i = 0; i < ArrNode.length; i++) 
 { 
  if (ArrNode[i].iChildren == 0) 
  { 
   str = ’.’; 
   opened = ’no’; 
   cls = ’dirNode’; 
  } 
  else 
  { 
   str = ’+’; 
   opened = ’false’; 
   cls = ’dirclose’; 
  } 
  node_html += ’<tr><td id="node’ + ArrNode[i].id + ’" class="td_node" valign="top"><span class="’ + cls + ’" id="dir’ + ArrNode[i].id + ’" onclick="expand(’ + ArrNode[i].id + ’)" open="’ + opened + ’">’ + str + ’</span><span class="node" id="s’ + ArrNode[i].id + ’" onclick="expand(’ + ArrNode[i].id + ’)" title="’ + ArrNode[i].Content + ’" href="’ + ArrNode[i].strLink + ’">’ + ArrNode[i].Content + ’</span></td></tr>’; 
  if (ArrNode[i].iChildren > 0) 
  { 
   node_html += ’<tr id="load_’ + ArrNode[i].id + ’" style="display: none"><td class="td_node"><table border="0" cellspacing="0" cellpadding="0" style="position: relative; left: 18; top: 0px"><tr><td class="td_node"><span class="dirNode">.</span><span class="load">Loading...</span></td></tr></table></td></tr>’; 
  } 
 } 
 node_html += ’</table>’; 
 if (document.getElementById("load_" + nodeid)) 
 { 
  document.getElementById("load_" + nodeid).style.display = "none"; 
  document.getElementById("node" + nodeid).innerHTML += node_html; 
  var d=new Date(); 
  d2=d.valueOf(); 
  message.innerHTML = "耗时:"+(d2-d1)+"ms"; 
 } 

--> 
</script> 
</head> 
<body topmargin="0" leftmargin="0" scroll="yes"> 
<% 
Dim conn,rs 
Dim s,open,cls 
On Error Resume Next 
Set conn = Server.CreateObject("ADODB.Connection") 
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.mappath("tree/tree.mdb") & ";Persist Security Info=False" 
Set rs = Server.CreateObject("ADODB.Recordset") 
rs.Open "select *,(select count(*) from deeptree where parentid = T.id) as children from deeptree T where parentid=0 order by parentid",conn,1,3 
%> 
<div id="message" style="height: 20px" align="center">   </div> 
<div align="center"> 
  <center> 
    <table border="0" width="100%" cellspacing="0" cellpadding="0" height="100%" bgcolor="#F2F2F2"> 
      <tr> 
        <td width="260" valign="top" align="left"> 
          <div id="treedir" style="overflow: auto; width: 30%; height: 100%;"> 
         <table border="0" cellspacing="0" cellpadding="0" style="position: relative; left: 18px; top: 20px;" width="100%"> 
   <% 
   Do While Not rs.EOF 
    If rs("children") = 0 Then 
     s = "." 
     open = "no" 
     cls = "dirNode" 
    Else  
     s = "+" 
     open = "false" 
     cls = "dirclose" 
    End If 
   %> 
         <tr> 
     <td id="node<% = rs("id")%>" class="td_node" valign="top"><span class="<% = cls %>" id="dir<% = rs("id") %>" onclick="expand(<%=rs("id")%>)" open="<% = open %>"><% = s %></span><span class="node" id="s<% = rs("id") %>" onclick="expand(<% = rs("id") %>)"  title="<% = Trim(rs("content")) %>" href="<% = Trim(rs("link")) %>"><% = rs("content") %></span> 
     </td> 
   </tr> 
   <% If rs("children") > 0 Then%> 
         <tr id="load_<% = rs("id") %>" style="display: none"> 
           <td class="td_node"> 
             <table border="0" cellspacing="0" cellpadding="0" style="position:relative;left:18;top:0" width="100%"> 
            <tr> 
              <td class="td_node"><span class="dirNode">.</span><span class="load">Loading...</span> 
                    </td> 
                  </tr> 
                </table> 
              </td> 
            </tr> 
   <%End If%> 
   <% 
    rs.MoveNext 
   Loop 
   %> 
          </table> 
        </div> 
      </td> 
    </table> 
  </center> 
</div> 
<% 
Set rs = Nothing 
Set conn = Nothing 
%> 
<iframe id=’hifm’ width=0 height=0 style="display: none" height="100%" width="100%"></iframe> 
</body> 
</html>


标签:asp,树
0
投稿

猜你喜欢

  • 防止网上重复投票的方法

    2009-06-01 12:31:00
  • MYSQL教程:数据列类型与查询效率

    2009-02-27 15:37:00
  • 学习ASP的理由 分析小结

    2011-02-26 10:54:00
  • 9个Web设计中常见的可用性错误[译]

    2009-03-11 20:25:00
  • 静态页面分页的AJAX实现

    2008-01-19 16:19:00
  • 再读《你是一个职业的页面重构工作者吗?》

    2009-02-11 12:22:00
  • 在ie6下的hover伪类的使用

    2008-06-01 13:51:00
  • CSS Position

    2009-05-17 14:27:00
  • 使用xmlhttp为网站增加股市行情查询功能

    2007-10-10 21:09:00
  • 解决mysql不能插入中文Incorrect string value

    2009-07-30 09:02:00
  • 恢复master..xp_logattach(log explorer)

    2010-07-01 19:19:00
  • SQL Server 数据库备份和还原认识和总结 (一)

    2012-10-07 10:52:54
  • SQL Server 2008 到底需要使用哪些端口?

    2012-11-30 20:29:41
  • ASP访问SQL Server内置对象

    2008-04-05 06:49:00
  • SQL Server 总结复习 (二)

    2012-10-07 10:35:00
  • 在网页设计中,如何使用图标来支持内容?[译]

    2009-03-16 16:35:00
  • XPath 11个实例

    2008-09-05 15:06:00
  • 聚焦 DreamWeaver MX 2004

    2010-03-25 12:22:00
  • SQL Server可写脚本和编程扩展SSIS包

    2009-01-20 16:29:00
  • CSS content, counter-increment 和 counter-reset详解[译]

    2009-06-02 12:51:00
  • asp之家 网络编程 m.aspxhome.com