下载首页 | 资讯中心 | 下载分类 | 最近更新 | 排 行 榜 | 国产软件 | 国外软件 | 汉化补丁 |
文章搜索: 分类 关键字 收藏本站设为首页
您的位置:首页网页设计ASP程序 → 动态载入树 (ASP+数据库)__教程
动态载入树 (ASP+数据库)__教程
日期:2007-5-20 0:37:36 人气:25     [ ]
 

//**********************  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>


///****************** subtree.asp *********************//

<%Option Explicit%>
<script language="JavaScript">
function NodeClass(id,Content,strLink,iChildren)
{
 //this.id=parseInt(id);
 this.id=id;
    this.Content=Content;
 this.strLink=strLink;
 this.iChildren=iChildren;
    //this.iChildren=parseInt(iChildren);
}

var ArrNode = new Array();
<%
Dim conn,rs,s,cls,href,Open
Dim nodeid,i
nodeid = Request.QueryString("id")
'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=" & nodeid & "",conn,1,3
i=0
Do While Not rs.EOF
 %>
 ArrNode[<%=i%>] = new NodeClass(<%=rs("id")%>,'<%=trim(rs("content"))%>','<%=trim(rs("link"))%>',<%=rs("children")%>);
 <%

 i=i+1
 rs.MoveNext
Loop

Set rs = Nothing
%>
parent.ArrToHtml(ArrNode,'<% = nodeid %>');
-->
</script>
<%
Set conn = Nothing
%>

//********************* node.htc *********************//

<PUBLIC:COMPONENT>
<PUBLIC:ATTACH EVENT="onmouseover" ONEVENT="fos()"/>
<PUBLIC:ATTACH EVENT="onmouseout" ONEVENT="blu()"/>
<PUBLIC:ATTACH EVENT="onselectstart" ONEVENT="st()"/>
<SCRIPT>
function fos(){
if(style.backgroundColor!='#ffffff'){
style.color="#000000"
style.border="1 solid #888888"
style.backgroundColor='#DDDDDD'
}
else
{style.color="#000000"
style.border="1 solid #999999"
style.backgroundColor='#ffffff'
}
}

function blu(){
if(style.backgroundColor!='#ffffff'){
style.color="#000000"
style.border="1 solid #f2f2f2"
style.backgroundColor='#f2f2f2'
}
else
{style.color="#000000"
style.border="1 solid #999999"
style.backgroundColor='#ffffff'
}
}

function st(){
return false;
}
</SCRIPT>
</PUBLIC:COMPONENT>

//***************************  style.css ****************//

body{font-size:12px}
#txt{font-size: 12px; color: #000000;  font-family: Courier New;border:1 solid #3366cc}
#hrf{font-size: 12px; color: #000000;  font-family: Courier New;border:1 solid #3366cc}
#sb{font-size: 12px; color: #000000;  font-family: Courier New;background-color:#d2e8ff;border:1 solid #3366cc;cursor:hand}
.node{position:relative;left:2;height:20;padding:3 3 1 3;font-size:12px;font-family: Courier New;cursor:hand;border:1 solid #f2f2f2;behavior:url(css/node.htc)}
.load{position:relative;left:2;height:20;padding:1 3 1 3;font-size:12px;font-family: Courier New;cursor:hand;border:1 solid #999999;background-color:#f2f2f2;color:#999999}
.td_node{height:22px}
#treedir{
}
span.diropen
{ padding-left:2px;
 overflow:hidden;
 line-height:3px;
 font-size:12px;
 padding-top:5px;
 width:11px;
 height:11px;
 border:solid 1px black;
 background-color:#ffffff;
 cursor:hand;
}
span.dirclose
{
 line-height:6px;
 font-size:9px;
 overflow:hidden;
 padding:2px;
 width:11px;
 height:11px;
 border:solid 1px black;
 background-color:#ffffff;
 cursor:hand;
}
.dirNode
{
 font-weight:bold
 overflow:visible;
 font-size:9px;
 line-height:3px;
 padding: 1px 1px 0px 3px;
 width:11px;
 height:11px;
 border:solid 1px black;
 background-color:#ffffff;
 cursor:hand;
}

// 把 node.htc, style.css 保存与 css 目录下. index.asp subtree.asp 放与根目录.
另新建一ACCESS数据库 tree.mdb
表deeptree 结构为 id,content, parentid,link

出处:本站原创 作者:佚名
 阅读排行
01.精美qq空间横幅代码
02.最酷qq个性女生网名
03.最新又有免费QQ秀啦《..
04.巧用透明FlaSh扮靓你的..
05.花之神匠代码(最新代码..
06.最新QQ空间免费导航
07.最新免费个人形象设置..
08.最新qq空间flash代码m..
09.CSS技术结合图像实现动..
10.Photoshop光影魔术师:..
11.QQ音速种子狂刷
12.最新QQ空间透明代码
13.PS实例教程:教你制作结..
14.Photoshop光影魔术师:..
15.制作背景图__教程
16.用Photoshop制作漂亮的..
17.如何获得QQ音速种子
18.≤QQ空间代码≥在日志..
19.网页浮动广告的制作代..
20.用Photoshop制作大红灯..
21.常用CSS
22.Photoshop给靓丽美女打..
 推荐文章
·Photoshop 表现技法之..
·快速将你的相片矢量化..
·PHOTOSHOP制作炽热的太..
·用Photoshop制作美丽的..
·流行杀手的娃娃工厂__..
·打造8号台球__教程
·PHOTOSHOP制作待机MM图..
·用Photoshop帮MM做纹身..
·PHOTOSHOP美眉着色绝招..
·PHOTOSHOP花露的制作_..
·PHOTOSHOP渐变工具的巧..
·PHOTOSHOP手绘奥兰多-..
·高难度抠图两种方法__..
·Photoshop高尔夫球的制..
·Photoshop打造精美玉佩..
Eqxia_COM下载站 版权所有 Copyright© 2001-2005 Www.eqxia.COM, All Rights Reserved.