ajax+asp 무한 분류 트 리 구조(데이터베이스 포함)
<%
' , 、 、 、
Class Cls_Leibie
Private nClassID,sClassName,nParentID,sParentPath,nDepth,nRootID,nChild,nOrderID,sFilePath ' ( , )
Private rs,sql,ErrorStr
Private Sub Class_Initialize()
ErrorStr="" '
End Sub
Private Sub Class_Terminate() '
If IsObject(Conn) Then
Conn.Close
Set Conn = Nothing
End If
End Sub
'******************* ******************************************************
Public Property Let ClassID(str) ' ID( )
nClassID=str
call ClassProperty() ' ID
End Property
Public Property Let ClassName(str) '
sClassName=str
End Property
Public Property Get ClassName
ClassName=sClassName
End Property
Public Property Let ParentID(str) ' ID
nParentID=str
End Property
Public Property Get ParentID
ParentID=nParentID
End Property
Public Property Let ParentPath(str) ' ID
sParentPath=str
End Property
Public Property Get ParentPath
ParentPath=sParentPath
End Property
Public Property Let Depth(str) '
nDepth=str
End Property
Public Property Get Depth
Depth=nDepth
End Property
Public Property Let RootID(str) ' ID
nRootID=str
End Property
Public Property Get RootID
RootID=nRootID
End Property
Public Property Let Child(str) '
nChild=str
End Property
Public Property Get Child
Child=nChild
End Property
Public Property Let OrderID(str) ' ID
nOrderID=str
End Property
Public Property Get OrderID
OrderID=nOrderID
End Property
Public Property Let FilePath(str) ' ( , Web , )
sFilePath=str
End Property
Public Property Get FilePath
FilePath=sFilePath
End Property
'******************************************************************************
Private Sub ClassProperty() '
sql="select * from ArticleClass where ClassID="& nClassID
set rs=conn.execute(sql)
if not rs.eof then
sClassName=trim(rs("ClassName"))
nParentID=trim(rs("ParentID"))
sParentPath=trim(rs("ParentPath"))
nDepth=trim(rs("Depth"))
nRootID=trim(rs("RootID"))
nChild=trim(rs("Child"))
nOrderID=trim(rs("OrderID"))
sFilePath=trim(rs("FilePath"))
end if
set rs=nothing
End Sub
Public Function FAddCheck() ' , 0 , 1 , , ErrorStr
dim temprs
FAddCheck=0
if sClassName="" then '
FAddCheck=1
ErrorStr=" !"
exit Function
else
if nParentID="" then ' id
FAddCheck=1
ErrorStr=" id !"
exit Function
else
if nParentID<>0 then
set temprs=conn.execute("select ClassID From ArticleClass where ClassID=" & nParentID) '
if temprs.eof then
FAddCheck=1
ErrorStr=" !"
exit Function
else
sql="select ClassID from ArticleClass where ClassName='"& sClassName &"' and ParentID="& nParentID '
set rs=conn.execute(sql)
if not rs.eof then
FAddCheck=1
ErrorStr=" !"
exit Function
end if
set rs=nothing
end if
set temprs=nothing
else
sql="select ClassID from ArticleClass where ClassName='"& sClassName &"' and ParentID="& nParentID '
set rs=conn.execute(sql)
if not rs.eof then
FAddCheck=1
ErrorStr=" !"
exit Function
end if
set rs=nothing
end if
end if
end if
End Function
Public Sub SAdd()
dim maxClassID,maxRootID
set rs = conn.execute("select Max(ClassID) from ArticleClass") ' id, 0, id id 1
maxClassID=rs(0)
if isnull(maxClassID) then
maxClassID=0
end if
set rs=nothing
nClassID=maxClassID+1
set rs=conn.execute("select max(rootid) From ArticleClass") ' id, 0, id id 1
maxRootID=rs(0)
if isnull(maxRootID) then
maxRootID=0
end if
nRootID=maxRootID+1
set rs=conn.execute("select RootID,Depth,ParentPath,Child,OrderID From ArticleClass where ClassID=" & nParentID) '
if not rs.eof then
nRootID=trim(rs("Rootid")) ' id id
sParentPath=trim(rs("ParentPath"))& "," &nParentID
if cint(trim(nParentID))>0 then ' id 0 , 1, id 0 , 0
nDepth=cint(trim(rs("Depth")))+1
else
nDepth=0
end if
if cint(trim(rs("Child")))>0 then
dim rsPrevOrderID
' OrderID
set rsPrevOrderID=conn.execute("select Max(OrderID) From ArticleClass where ParentID=" & ParentID)
prevOrderID=rsPrevOrderID(0)
' OrderID, , 。
set rsPrevOrderID=conn.execute("select Max(OrderID) From ArticleClass where ParentPath like '" & ParentPath & ",%'")
if (not(rsPrevOrderID.bof and rsPrevOrderID.eof)) then
if not IsNull(rsPrevOrderID(0)) then
if rsPrevOrderID(0)>prevOrderID then
prevOrderID=rsPrevOrderID(0)
end if
end if
end if
set rsPrevOrderID=nothing
end if
nOrderID=prevOrderID+1
else
nOrderID=0
sParentPath="0"
nDepth=0
end if
set rs=nothing
nChild=0
sql="insert into ArticleClass (ClassID,ClassName,ParentID,ParentPath,Depth,RootID,Child,OrderID,FilePath) values ("& nClassID &",'"& sClassName &"',"& nParentID &",'"& sParentPath &"',"& nDepth &","& nRootID &","& nChild &","& nOrderID &",'"& sFilePath &"')"
conn.execute(sql)
if ParentID>0 then
'
conn.execute("update ArticleClass set child=child+1 where ClassID="& nParentID)
'
if prevOrderID<>"" then
conn.execute("update ArticleClass set OrderID=OrderID+1 where rootid=" & nRootid & " and OrderID>"& prevOrderID &" and ClassID<>"& nClassID)
end if
end if
End Sub
Public Function FEditCheck() ' , 0 , 1 , , ErrorStr
dim temprs
FEditCheck=0
if nClassID="" then ' id
FEditCheck=1
ErrorStr=" id !"
exit Function
else
if sClassName="" then '
FEditCheck=1
ErrorStr=" !"
exit Function
else
if nParentID<>0 then
set temprs=conn.execute("select ClassID From ArticleClass where ClassID=" & nParentID) '
if temprs.eof then
FAddCheck=1
ErrorStr=" !"
exit Function
else
set rs=conn.execute("select ClassID from ArticleClass where ClassName='"& sClassName &"' and ClassID<>"& nClassID &"and ParentID="& nParentID)
if not rs.eof then '
FEditCheck=1
ErrorStr=" !"
exit Function
end if
set rs=nothing
end if
set temprs=nothing
end if
end if
end if
End Function
Public Sub SEdit() '
sql="update ArticleClass set ClassName='"& sClassName &"',FilePath='"& sFilePath &"' where ClassID="& nClassID
conn.execute(sql)
End Sub
Public Function FDeleteCheck() ' , 0 , 1 , , ErrorStr
FDeleteCheck=0 ' ,
if nClassID="" then
FDeleteCheck=1
ErrorStr=" id !"
exit Function
else
set rs=conn.execute("select Child from ArticleClass where ClassID="& nClassID)
if rs.bof and rs.eof then
FDeleteCheck=1
ErrorStr=" !"
exit Function
else
if trim(rs("Child"))>0 then
FDeleteCheck=1
ErrorStr=" , !"
exit Function
end if
end if
end if
End Function
Public Sub SDelete()
if nDepth>0 then ' id
conn.execute("update ArticleClass set child=child-1 where child>0 and ClassID=" & nParentID)
end if
sql="delete from ArticleClass where ClassID="& nClassID
conn.execute(sql)
End Sub
Public Function FErrStr()
FErrStr=ErrorStr
End Function
End Class
%>
index.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
' :www.guaishi.org
' :[email protected]
'QQ:514777880
Session.CodePage=65001
Response.Charset = "utf-8"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
body{margin:0;padding:0;font-size:12px; background-color:#FFFFFF;}
ul{ list-style-type:none; margin:0 0 0 20px; padding:0;}
li{ white-space:nowrap; padding:0;}
.childdiv{ background:url(images/dot.gif);background-repeat:repeat-y;}
span { cursor:pointer;}
</style>
<script type="text/javascript">
var xmlHttp; //
var currentID=1;// ID, ID js
//
//cid-- id
//id -- id
//pid--[+] [-] id
//fid-- id
function DivDisplay(cid,id,pid,fid)
{
if (GetId(cid).style.display=='') //
{
GetId(cid).style.display='none';
GetId(pid).src = 'images/closed.gif';
GetId(fid).src = 'images/folder.gif';
}
else //
{
GetId(cid).style.display='';
GetId(pid).src = 'images/opened.gif';
GetId(fid).src = 'images/folderopen.gif';
if (GetId(cid).innerHTML==''||GetId(cid).innerHTML==' ...')
{
GetId(cid).innerHTML='';
ShowChild(cid,id); //
}
}
}
// ,
function DivDisplay2(cid,id,pid,fid)
{
if (GetId(cid).style.display=='')
{
GetId(cid).style.display='none';
GetId(pid).src = 'images/lastclosed.gif';
GetId(fid).src = 'images/folder.gif';
}
else
{
GetId(cid).style.display='';
GetId(pid).src = 'images/lastopen.gif';
GetId(fid).src = 'images/folderopen.gif';
if (GetId(cid).innerHTML==''||GetId(cid).innerHTML==' ...')
{
GetId(cid).innerHTML='';
ShowChild(cid,id);
}
}
}
//
//id-- id
function ClassAdd(id){
if (GetId("p"+id).src.indexOf("last")>0){ //
if (!GetId("p"+id).onclick){
GetId("p"+id).onclick=function (){DivDisplay2("c"+id,id,"p"+id,"f"+id);}; // [+] [-]
GetId("s"+id).ondblclick=function (){DivDisplay2("c"+id,id,"p"+id,"f"+id);}; // span
GetId("p"+id).src = 'images/lastopen.gif';
}
}
else{
if (!GetId("p"+id).onclick){ //
GetId("p"+id).onclick=function (){DivDisplay("c"+id,id,"p"+id,"f"+id);};
GetId("s"+id).ondblclick=function (){DivDisplay("c"+id,id,"p"+id,"f"+id);};
GetId("p"+id).src = 'images/opened.gif';
}
}
GetId("c"+id).style.display='';
ShowChild("c"+id,id);
}
//
function ClassEdit(id,classname){
GetId("s"+id).innerHTML=classname;
}
//
function ClassDel(id){
ShowChild("c"+id,id);
CurrentSelect(currentID,id)
BrowseRight(id);
}
//
function ClassDel1(id){
if (GetId("p"+id).src.indexOf("last")>0){ //
GetId("p"+id).style.cursor="cursor"; //
GetId("p"+id).onclick=function (){}; // ,
GetId("s"+id).ondblclick=function (){}; //
GetId("p"+id).src = 'images/lastnochild.gif'; //
}
else{
GetId("p"+id).style.cursor="cursor"; //
GetId("p"+id).onclick=function (){};
GetId("s"+id).ondblclick=function (){};
GetId("p"+id).src = 'images/nofollow2.gif'; //
}
ShowChild("c"+id,id);
CurrentSelect(currentID,id);
BrowseRight(id);
}
//
function BrowseRight(id){
CurrentSelect(currentID,id);
top.ContentFrame.location="../ArticleMain.asp?ClassID="+ id;
}
//
function CurrentSelect(oldid,newid){
currentID=newid;
document.getElementById("s"+oldid).style.backgroundColor="white";
document.getElementById("s"+currentID).style.backgroundColor="#C0C0E9";
}
// XMLHttpRequest
function CreateXMLHttpRequest()
{
if (window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
xmlHttp = new XMLHttpRequest();
}
}
//Ajax
//id, id
//rid, id
function ShowChild(cid,id)
{
CreateXMLHttpRequest();
if(xmlHttp)
{
xmlHttp.open('POST','child.asp',true);
xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
var SendData = 'id='+id;
xmlHttp.send(SendData);
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
GetId(cid).innerHTML = xmlHttp.responseText;
}
else
{
GetId(cid).innerHTML=' :'+xmlHttp.statusText;
}
}
else
{
GetId(cid).innerHTML=" ...";
}
}
}
else
{
GetId(cid).innerHTML=' , XMLHttpRequest, IE6 !';
}
}
//
//id, id
function GetId(id)
{
return document.getElementById(id);
}
</script>
</head>
<body>
<!--#include file="../conn.asp"-->
<%
'
sql="select *,(select top 1 ClassID from ArticleClass where Depth=0 order by ClassID desc) as lastid from ArticleClass where Depth=0 order by ClassID"
set rs=conn.execute(sql)
if not rs.eof then
response.Write "<ul>"&vbcr
do while not rs.eof
if cint(trim(rs("ClassID")))=cint(trim(rs("lastid"))) then
if rs("Child")>0 then
response.Write "<li><img id='p"&rs("ClassID")&"' src=""images/lastclosed.gif"" onclick=""DivDisplay2('c"&rs("ClassID")&"','"&rs("ClassID")&"','p"&rs("ClassID")&"','f"& rs("ClassID") &"')"" style=""cursor : hand;"" align=""absmiddle"">"
response.Write "<img src=""images/folder.gif"" align=""absmiddle"" id='f"& rs("ClassID") &"' /> <span id='s"& trim(rs("ClassID")) &"' onclick=""BrowseRight("& trim(rs("ClassID")) &")"" ondblclick=""DivDisplay2('c"&rs("ClassID")&"','"&rs("ClassID")&"','p"&rs("ClassID")&"','f"& rs("ClassID") &"')"">"& rs("ClassName") &"</span>"
else
response.Write "<li><img id='p"& rs("ClassID") &"' src=""images/lastnochild.gif"" align=""absmiddle"" />"
response.Write "<img src=""images/folder.gif"" align=""absmiddle"" id='f"& rs("ClassID") &"' /> <span id='s"& trim(rs("ClassID")) &"' onclick=""BrowseRight("& trim(rs("ClassID")) &")"">"& rs("ClassName") &"</span>"
end if
else
if rs("Child")>0 then
response.Write "<li><img id='p"&rs("ClassID")&"' src=""images/closed.gif"" onclick=""DivDisplay('c"&rs("ClassID")&"','"&rs("ClassID")&"','p"&rs("ClassID")&"','f"& rs("ClassID") &"')"" style=""cursor : hand;"" align=""absmiddle"">"
response.Write "<img src=""images/folder.gif"" align=""absmiddle"" id='f"& rs("ClassID") &"' /> <span id='s"& trim(rs("ClassID")) &"' onclick=""BrowseRight("& trim(rs("ClassID")) &")"" ondblclick=""DivDisplay('c"&rs("ClassID")&"','"&rs("ClassID")&"','p"&rs("ClassID")&"','f"& rs("ClassID") &"')"">"& rs("ClassName") &"</span>"
else
response.Write "<li><img id='p"& rs("ClassID") &"' src=""images/nofollow2.gif"" align=""absmiddle"" />"
response.Write "<img src=""images/folder.gif"" align=""absmiddle"" id='f"& rs("ClassID") &"' /> <span id='s"& trim(rs("ClassID")) &"' onclick=""BrowseRight("& trim(rs("ClassID")) &")"">"& rs("ClassName") &"</span>"
end if
end if
if cint(trim(rs("ClassID")))=cint(trim(rs("lastid"))) then
response.Write "<div id='c"&rs("ClassID")&"' style='display:none;'></div>"
else
response.Write "<div id='c"&rs("ClassID")&"' style='display:none;' class=""childdiv""></div>"
end if
response.Write "</li>"&vbcr
rs.movenext
loop
response.Write "</ul>"&vbcr
end if
rs.close
set rs=nothing
conn.close
Set conn = Nothing
%>
</body>
</html>
포장 다운로드 주소http://xiazai.jb51.net/200906/yuanma/ajaxtree_51281.rar
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Javascript Ajax에 대한 간단한 연습저는 약 4년 동안 프로그래밍 개인 튜터로 일한 경험이 있습니다. 약 5년 전에 " "이라는 제목의 페르시아어로 내 웹사이트에 블로그 게시물을 올렸고 사람들이 저에게 전화하기 시작했습니다. 나는 항상 사람들을 가르치...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.