程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Access數據庫 >> 關於Access數據庫 >> 使用DW用ASP+ACCESS編寫目錄樹

使用DW用ASP+ACCESS編寫目錄樹

編輯:關於Access數據庫
·Nero 6高級使用圖解
·Eclips使用秘技(絕對經典)
·電腦使用常見問題解答
·摳圖—背景橡皮擦工具的使用
·COPY命令使用說明
·享受急速:四大主流網游加速器使用對比
·高速下載+在線觀看 風播BT使用教程
·OCR軟件使用寶典
·IE使用技巧大全——基本技巧篇
·mental ray節點和燈光使用教程
  利用Access創建數據庫listBase.mdb:
  數據表:listTable
  數據字段:listId    listName    listInfo    parentId

  連接方法:
<%
    dim sConn,sConnStr,sSql
    sConnStr="DRIVER={Microsoft Access Driver (*.mdb)};dbq=" & server.mappath("listBase.mdb")
    set sConn=server.createobject("adodb.connection")
    sConn.open sConnStr
%>

  把以上代碼保存成文件:initialize.ASP

  下面這段程序代碼是用來顯示目錄樹用的,保存成文件:inc.ASP

<!--#include file="initialize.ASP"-->
<script language=JScript>
<!--
//此函數用來顯示與關閉它的子菜單的,並切換其前面的小圖片
function showMenu(menuObj,isSub){
if(menuObj.style.display=="none"){
menuObj.style.display="";
if(isSub==1){
event.srcElement.src="images/open.gif";
}
}
else{
menuObj.style.display="none";
if(isSub==1){
event.srcElement.src="images/close.gif";
}
}
}
//-->
</script>
<!--下面這段藍色的區域,是設置目錄樹的根,其中的內容非數據內的數據,數據庫內的數據都附著在它的下面//-->
<%
response.write("<table width='100%' border='0' cellspacing='0' cellpadding='0'>" & chr(13))
response.write("<tr>" & chr(13)&"<td>" & chr(13) & "<table width='100%' border='0' cellspacing='0' cellpadding='0'>")
response.write("<tr>" & chr(13) & "<td width='18' ><img src='images/root.gif' onclick='JScript:showMenu(subMenu0,0)' style='cursor:hand' alt='不可修改'></td>" & chr(13) & "<td width='100' class='menuPro' id='listName0'>根節點</td>" & chr(13))
response.write("<td width='40' class='menuFont' align='center' style='cursor:hand' onclick=""JScript:showForm('add',0)"">添加</td>" & chr(13))
response.write("<td width='40' class='menuFont' align='center' onclick=''></td>" & chr(13))
response.write("<td>&nbsp;</td></tr></table></td></tr>" & chr(13))
response.write("<tr id='subMenu0'>" & chr(13) & "<td colspan='2'>" & chr(13))
'此處調用顯示目錄樹的遞歸函數
listChild(0)
response.write("</td>" & chr(13) & "</tr>" & chr(13) & "</table>" & chr(13))


'下面代碼為顯示目錄樹最關鍵的函數,使用了遞歸方法(很多象這樣類型的都是用遞歸來做的。)
function listChild(id)
dim sRec,sSql,sNum,sTmp
set sRec=server.createobject("adodb.recordset")
sSql="select listId,listName,listInfo,parentId from listTable where parentId=" & id
sRec.open sSql,sConn,3,1
if not sRec.eof then
sNum=1
response.write("<table width='100%' border='0' cellspacing='0' cellpadding='0'>" & chr(13))
while not sRec.eof
sTmp=sConn.execute("select count(listId) as countSub from listTable where parentId=" & sRec("listId"))
if sTmp("countSub")>0 then
response.write("<tr>" & chr(13))
if sNum=sRec.recordcount then
response.write("<td width='18' valign='top'><img src='images/angel.gif'></td>" & chr(13))
else
response.write("<td width='18' background='images/eline.gif' valign='top'><img src='images/t.gif' ></td>" & chr(13))
end if
response.write("<td>" & chr(13) & "<table width='100%' border='0' cellspacing='0' cellpadding='0'>" & chr(13))
response.write("<tr>" & chr(13) & "<td width='118' class='menuPro' id='listName" & sRec("listId") & "'><img id='img" & sRec("listId") & "' style='cursor:hand' src='images/close.gif' align='absMiddle' onclick='JScript:showMenu(subMenu" & sRec("listId") & ",1)' alt='" & sRec("listInfo") & "'>" & server.HtmlEncode(sRec("listName")) & "</td>" & chr(13) & "<td width='40' class='menuFont'><div align='center' style='cursor:hand' onclick=""jscript:showForm('add'," & sRec("listId") & ")"">添加</div></td><td width='40' class='menuFont'><div align='center' style='cursor:hand' onclick=""JScript:showForm('edit'," & sRec("listId") & ")"">編輯</div></td>" & chr(13))
response.write("<td width='40' class='menuFont'><div align='center' style='cursor:hand' onclick=""JScript:window.location='disp.ASP?disp=del&parentId=" & sRec("listId") & "'"">刪除 </div></td>" & chr(13) & "<td>&nbsp;</td>" & chr(13) & "</tr>" & chr(13) & "</table>" & chr(13) & "</td>" & chr(13) & "</tr>" & chr(13))
response.write("<tr id='subMenu" & sRec("listId") &"' style='display:none'>")
if sNum=sRec.recordcount then
response.write("<td width='18' valign='top'")
response.write("<img src='images/angel.gif' >")
response.write("</td>" & chr(13))
else
response.write("<td width='18' valign='top' background='images/eline.gif'>")
response.write("</td>" & chr(13))
end if
response.write("<td>" & chr(13))
listChild(sRec("listid"))
response.write("</td>" & chr(13) & "</tr>" & chr(13))
else
response.write("<tr>" & chr(13))
if sNum=sRec.recordcount then
response.write("<td width='18' valign='top'><img src='images/angel.gif'></td>" & chr(13))
else
response.write("<td width='18' background='images/eline.gif' valign='top'><img src='images/t.gif' ></td>" & chr(13))
end if
response.write("<td>" & chr(13) & "<table width='100%' border='0' cellspacing='0' cellpadding='0'>" & chr(13))
response.write("<tr>" & chr(13) & "<td width='118' class='menuPro' id='listName" & sRec("listId") & "'><img id='img" & sRec("listId") & "' src='images/file.gif' align='absMiddle' alt='" & sRec("listInfo") & "'>" & server.HtmlEncode(sRec("listName")) & "</td>" & chr(13) & "<td width='40' class='menuFont'><div align='center' style='cursor:hand' onclick=""jscript:showForm('add'," & sRec("listId") & ")"">添加</div></td><td width='40' class='menuFont'><div align='center' style='cursor:hand' onclick=""JScript:showForm('edit'," & sRec("listId") & ")"&uot;>編輯</div></td>" & chr(13))
response.write("<td width='40' class='menuFont'><div align='center' style='cursor:hand' onclick=""JScript:window.location='disp.ASP?disp=del&parentId=" & sRec("listId") & "'"">刪除</div></td>" & chr(13) & "<td>&nbsp;</td>" & chr(13) & "</tr>" & chr(13) & "</table>" & chr(13) & "</td>" & chr(13) & "</tr>" & chr(13))
end if
sRec.movenext
sNum=sNum+1
wend
response.write("</table>" & chr(13))
end if
sRec.close '關閉記錄集
set sRec=nothing '關閉記錄集
end function
sConn.close '關閉數據庫鏈接
set sConn=nothing '關閉數據庫鏈接
%>

·Nero 6高級使用圖解
·Eclips使用秘技(絕對經典)
·電腦使用常見問題解答
·摳圖—背景橡皮擦工具的使用
·COPY命令使用說明
·享受急速:四大主流網游加速器使用對比
·高速下載+在線觀看 風播BT使用教程
·OCR軟件使用寶典
·IE使用技巧大全——基本技巧篇
·mental ray節點和燈光使用教程
  下面這是調用頁代碼,保存成index.ASP

<%@LANGUAGE='VBSCRIPT' CODEPAGE='936'%>
<Html>
<head>
<meta http-equiv='Content-Type' content='text/Html; charset=gb2312'>
<title>目錄樹</title>
<script language='Javascript' type='text/JavaScript'>
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=='Netscape')&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
<script language="JScript">
<!--

//此函數設置處理表單的內容
//比如添加時,表單為空,並顯示為什麼節點添加子節點
//比如修改時,表單內為相應節點的內容,並顯示在修改什麼節點


function showForm(disp,parentId){
addNodeDiv.style.display="";
document.all.addNodeForm.disp.value=disp;
document.all.addNodeForm.parentId.value=parentId;
if(disp=="edit"){
document.all.addNodeForm.listInfo.value=eval("img"+parentId+".alt");
document.all.addNodeForm.listName.value=eval("listName"+parentId+".innerText");
infoValue.innerText="編輯["+eval("listName"+parentId+".innerText")+"]節點";
}
else{
document.all.addNodeForm.listInfo.value="";
document.all.addNodeForm.listName.value="";
infoValue.innerText="給節點["+eval("listName"+parentId+".innerText")+"]添加子節點";
}
}


<!--這棕色部分為移動表單代碼,可以不要。//-->
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_dragLayer(objName,x,hL,hT,hW,hH,toFront,dropBack,cU,cD,cL,cR,targL,targT,tol,dropJS,et,dragJS) { //v4.01
//Copyright 1998 Macromedia, Inc. All rights reserved.
var i,j,aLayer,retVal,curDrag=null,curLeft,curTop,IE=document.all,NS4=document.layers;
var NS6=(!IE&&document.getElementById), NS=(NS4||NS6); if (!IE && !NS) return false;
retVal = true; if(IE && event) event.returnValue = true;
if (MM_dragLayer.arguments.length > 1) {
curDrag = MM_findObj(objName); if (!curDrag) return false;
if (!document.allLayers) { document.allLayers = new Array();
with (document) if (NS4) { for (i=0; i<layers.length; i++) allLayers[i]=layers[i];
for (i=0; i<allLayers.length; i++) if (allLayers[i].document && allLayers[i].document.layers)
with (allLayers[i].document) for (j=0; j<layers.length; j++) allLayers[allLayers.length]=layers[j];
} else {
if (NS6) { var spns = getElementsByTagName("span"); var all = getElementsByTagName("div");
for (i=0;i<spns.length;i++) if (spns[i].style&&spns[i].style.position) allLayers[allLayers.length]=spns[i];}
for (i=0;i<all.length;i++) if (all[i].style&&all[i].style.position) allLayers[allLayers.length]=all[i];
} }
curDrag.MM_dragOk=true; curDrag.MM_targL=targL; curDrag.MM_targT=targT;
curDrag.MM_tol=Math.pow(tol,2); curDrag.MM_hLeft=hL; curDrag.MM_hTop=hT;
curDrag.MM_hWidth=hW; curDrag.MM_hHeight=hH; curDrag.MM_toFront=toFront;
curDrag.MM_dropBack=dropBack; curDrag.MM_dropJS=dropJS;
curDrag.MM_everyTime=et; curDrag.MM_dragJS=dragJS;
curDrag.MM_oldZ = (NS4)?curDrag.zIndex:curDrag.style.zIndex;
curLeft= (NS4)?curDrag.left:(NS6)?parseInt(curDrag.style.left):curDrag.style.pixelLeft;
if (String(curLeft)=="NaN") curLeft=0; curDrag.MM_startL = curLeft;
curTop = (NS4)?curDrag.top:(NS6)?parseInt(curDrag.style.top):curDrag.style.pixelTop;
if (String(curTop)=="NaN") curTop=0; curDrag.MM_startT = curTop;
curDrag.MM_bL=(cL<0)?null:curLeft-cL; curDrag.MM_bT=(cU<0)?null:curTop-cU;
curDrag.MM_bR=(cR<0)?null:curLeft+cR; curDrag.MM_bB=(cD<0)?null:curTop+cD;
curDrag.MM_LEFTRIGHT=0; curDrag.MM_UPDOWN=0; curDrag.MM_SNAPPED=false; //use in your JS!
document.onmousedown = MM_dragLayer; document.onmouseup = MM_dragLayer;
if (NS) document.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
} else {
var theEvent = ((NS)?objName.type:event.type);
if (theEvent == 'mousedown') {
var mouseX = (NS)?objName.pageX : event.clIEntX + document.body.scrollLeft;
var mouseY = (NS)?objName.pageY : event.clIEntY + document.body.scrollTop;
var maxDragZ=null; document.MM_maxZ = 0;
for (i=0; i<document.allLayers.length; i++) { aLayer = document.allLayers[i];
var aLayerZ = (NS4)?aLayer.zIndex:parseInt(aLayer.style.zIndex);
if (aLayerZ > document.MM_maxZ) document.MM_maxZ = aLayerZ;
var isVisible = (((NS4)?aLayer.visibility:aLayer.style.visibility).indexOf('hid') == -1);
if (aLayer.MM_dragOk != null && isVisible) with (aLayer) {
var parentL=0; var parentT=0;
if (NS6) { parentLayer = aLayer.parentNode;
while (parentLayer != null && parentLayer.style.position) {
parentL += parseInt(parentLayer.offsetLeft); parentT += parseInt(parentLayer.offsetTop);
parentLayer = parentLayer.parentNode;
} } else if (IE) { parentLayer = aLayer.parentElement;
while (parentLayer != null && parentLayer.style.position) {
parentL += parentLayer.offsetLeft; parentT += parentLayer.offsetTop;
parentLayer = parentLayer.parentElement; } }
var tmpX=mouseX-(((NS4)?pageX:((NS6)?parseInt(style.left):style.pixelLeft)+parentL)+MM_hLeft);
var tmpY=mouseY-(((NS4)?pageY:((NS6)?parseInt(style.top):style.pixelTop) +parentT)+MM_hTop);
if (String(tmpX)=="NaN") tmpX=0; if (String(tmpY)=="NaN") tmpY=0;
var tmpW = MM_hWidth; if (tmpW <= 0) tmpW += ((NS4)?clip.width :offsetWidth);
var tmpH = MM_hHeight; if (tmpH <= 0) tmpH += ((NS4)?clip.height:offsetHeight);
if ((0 <= tmpX && tmpX < tmpW && 0 <= tmpY && tmpY < tmpH) && (maxDragZ == null
|| maxDragZ <= aLayerZ)) { curDrag = aLayer; maxDragZ = aLayerZ; } } }
if (curDrag) {
document.onmousemove = MM_dragLayer; if (NS4) document.captureEvents(Event.MOUSEMOVE);
curLeft = (NS4)?curDrag.left:(NS6)?parseInt(curDrag.style.left):curDrag.style.pixelLeft;
curTop = (NS4)?curDrag.top:(NS6)?parseInt(curDrag.style.top):curDrag.style.pixelTop;
if (String(curLeft)=="NaN") curLeft=0; if (String(curTop)=="NaN&quo;) curTop=0;
MM_oldX = mouseX - curLeft; MM_oldY = mouseY - curTop;
document.MM_curDrag = curDrag; curDrag.MM_SNAPPED=false;
if(curDrag.MM_toFront) {
eval('curDrag.'+((NS4)?'':'style.')+'zIndex=document.MM_maxZ+1');
if (!curDrag.MM_dropBack) document.MM_maxZ++; }
retVal = false; if(!NS4&&!NS6) event.returnValue = false;
} } else if (theEvent == 'mousemove') {
if (document.MM_curDrag) with (document.MM_curDrag) {
var mouseX = (NS)?objName.pageX : event.clIEntX + document.body.scrollLeft;
var mouseY = (NS)?objName.pageY : event.clIEntY + document.body.scrollTop;
newLeft = mouseX-MM_oldX; newTop = mouseY-MM_oldY;
if (MM_bL!=null) newLeft = Math.max(newLeft,MM_bL);
if (MM_bR!=null) newLeft = Math.min(newLeft,MM_bR);
if (MM_bT!=null) newTop = Math.max(newTop ,MM_bT);
if (MM_bB!=null) newTop = Math.min(newTop ,MM_bB);
MM_LEFTRIGHT = newLeft-MM_startL; MM_UPDOWN = newTop-MM_startT;
if (NS4) {left = newLeft; top = newTop;}
else if (NS6){style.left = newLeft; style.top = newTop;}
else {style.pixelLeft = newLeft; style.pixelTop = newTop;}
if (MM_dragJS) eval(MM_dragJS);
retVal = false; if(!NS) event.returnValue = false;
} } else if (theEvent == 'mouseup') {
document.onmousemove = null;
if (NS) document.releaseEvents(Event.MOUSEMOVE);
if (NS) document.captureEvents(Event.MOUSEDOWN); //for Mac NS
if (document.MM_curDrag) with (document.MM_curDrag) {
if (typeof MM_targL =='number' && typeof MM_targT == 'number' &&
(Math.pow(MM_targL-((NS4)?left:(NS6)?parseInt(style.left):style.pixelLeft),2)+
Math.pow(MM_targT-((NS4)?top:(NS6)?parseInt(style.top):style.pixelTop),2))<=MM_tol) {
if (NS4) {left = MM_targL; top = MM_targT;}
else if (NS6) {style.left = MM_targL; style.top = MM_targT;}
else {style.pixelLeft = MM_targL; style.pixelTop = MM_targT;}
MM_SNAPPED = true; MM_LEFTRIGHT = MM_startL-MM_targL; MM_UPDOWN = MM_startT-MM_targT; }
if (MM_everyTime || MM_SNAPPED) eval(MM_dropJS);
if(MM_dropBack) {if (NS4) zIndex = MM_oldZ; else style.zIndex = MM_oldZ;}
retVal = false; if(!NS) event.returnValue = false; }
document.MM_curDrag = null;
}
if (NS) document.routeEvent(objName);
} return retVal;
}
//-->
</script>
<link href='css/css.css' rel='stylesheet' type='text/CSS'>
</head>

<body bgcolor="#4A8CCE" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<div id="addNodeDiv" style="position:absolute; left:400; top:300; width:300; height:135; z-index:1;display:none;" class="formDiv" onMouseDown="MM_dragLayer('addNodeDiv','',1,1,300,30,true,false,-1,-1,-1,-1,false,false,0,'',false,'')">
<form action="disp.ASP" method="get" name="addNodeForm" id="addNodeForm">
<table width="300" border="0" cellspacing="0" cellpadding="3">
<tr style="cursor:hand">
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div id="infoValue" class="menuFont"></div></td>
<td><div align="right">
<input name="parentId" type="hidden" id="parentId">
<input name="disp" type="hidden" id="disp">
<img src="images/close2.gif" alt="點擊關閉" width="13" height="13" style="cursor:hand" onclick="JScript:addNodeDiv.style.display='none';"></div></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="70" class="menuFont">
<div align="right">節點名稱:</div></td>
<td width="120"><input name="listName" type="text" class="text1" id="listName"></td>
<td class="menuFont">10個字符BR> </tr>
<tr>
<td width="70">
<div align="right" class="menuFont">節點說明:</div></td>
<td><textarea name="listInfo" cols="19" rows="3" class="text1" id="listInfo"></textarea></td>
<td class="menuFont">50個字符</td>
</tr>
<tr>
<td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="80">&nbsp;</td>
<td width="40"> <input name="SubmitBut" type="submit" class="DivBut" id="SubmitBut" value="提交" onclick="JScript:addNodeForm.submit();this.disabled='disabled'">
</td>
<td width="10">&nbsp;</td>
<td width="40"> <input name="cancelBut" type="button" class="DivBut" id="cancelBut" onclick="JScript:addNodeDiv.style.display='none';" value="取消">
</td>
<td>&nbsp;</td>
</tr>
</table></td>
<td>&nbsp;</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</div>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<!--此處為包含文件//-->
<div id="Layer1" class="treeDiv">
<!--#include file="inc.ASP"-->
</div>
</td>
</tr>
</table>
</body>
</Html>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved