The effects of the left navigation tree of msdn and csdn are that when you click the parent node, a request is sent to fill its subnodes! It seems that the webpage only refreshes parts! Javascript + [ASP + ACCESS] Implementation
SourceProgramDownload: http://www.triaton.com.cn/Private/Zip/Tree.zip
<! -- Tree. asp -->
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> new document </title>
<Meta name = "generator" content = "editplus">
<Meta name = "author" content = "">
<Meta name = "keywords" content = "">
<Meta name = "Description" content = "">
</Head>
<Body>
<IFRAME width = "100%" Height = "30" id = "hiddenframe"> </iframe>
<SCRIPT>
Function expandnode (parentnode, parentid ){
VaR nodex = eval (parentnode. ID + '_ 0 ');
If (nodex. style. Display = 'None ')
{
Nodex. style. Display = "Block ";
If (nodex. Loaded = 'no ')
{
Document. Frames ['dendenframework']. Location. Replace ("http: // localhost/dvbbs/subtree. asp? PID = "+ parentid +" & pnode = "+ parentnode. ID );
Nodex. Loaded = 'yes ';
}
}
Else
{
Nodex. style. Display = 'none ';
}
}
</SCRIPT>
<Center>
<Table border = "1" width = "20%" Height = "60%">
<Tr>
<TD>
<Div style = "overflow: auto; width: 100%; Height: 100%">
<Table width = 300%>
<Tr>
<TD>
<%
Dim adoconnection
Set adoconnection = server. Createobject ("ADODB. Connection ")
'Adoconnection. Open "provider = sqloledb.1; persist Security info = false; user id = sa; initial catalog = test; Data Source = triaton/psql2ke"
Adoconnection. Open "provider = Microsoft. Jet. oledb.4.0; Data Source =" & server. mappath ("/dvbbs") & "/tree. mdb; persist Security info = false"
Dim adorecordset
Set adorecordset = server. Createobject ("ADODB. recordset ")
Adorecordset. Open "select *, (select count (*) from tree where parentid = T. ID) as children from tree T where rootid = ID", adoconnection
Dim I
I = 0
Do until adorecordset. EOF
%>
<Div id = 'node _ <% = I %> '>
<A href = '#'
<% If adorecordset. Fields. Item ("children"). value> 0 then %>
Onclick = 'pandnode (node _ <% = I %>, <% = adorecordset. Fields. Item ("ID"). Value %>) '> + </a>
<% Else %>
>-</A>
<% End if %>
<A href = '# 'ondblclick =' expandnode (node _ <% = I %>, <% = adorecordset. fields. item ("ID "). value %>) '> <% = adorecordset. fields. item ("remark "). value %> </a>
</Div>
<Div id = 'node _ <% = I %> _ 0' style = 'display: none' loaded = 'no'>
& Nbsp; loading...
</Div>
<% I = I + 1
Adorecordset. movenext
Loop
Adorecordset. Close
Set adorecordset = nothing
Adoconnection. Close
Set adoconnection = nothing
%>
</TD>
</Tr>
</Table>
</Div>
</TD>
</Tr>
</Table>
</Center>
</Body>
</Html>
<! -- Subtree. asp -->
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> new document </title>
<Meta name = "generator" content = "editplus">
<Meta name = "author" content = "">
<Meta name = "keywords" content = "">
<Meta name = "Description" content = "">
</Head>
<Body>
<%
Dim parentid
Parentid = request. querystring ("PID ")
Parentnode = request. querystring ("parentnode ")
Dim adoconnection
Set adoconnection = server. Createobject ("ADODB. Connection ")
'Adoconnection. Open "provider = sqloledb.1; persist Security info = false; user id = sa; initial catalog = test; Data Source = triaton/psql2ke"
Adoconnection. Open "provider = Microsoft. Jet. oledb.4.0; Data Source =" & server. mappath ("/dvbbs") & "/tree. mdb; persist Security info = false"
Dim adorecordset
Set adorecordset = server. Createobject ("ADODB. recordset ")
Adorecordset. Open "select *, (select count (*) from tree where parentid = T. ID) as children from tree T where parentid =" & parentid, adoconnection
Response. Write adorecordset. Source
Dim I
Dim shtml
Dim parentnode
Parentnode = request. querystring ("pnode ")
Dim J
J = Len (parentnode)-len (replace (parentnode ,"_",""))
Dim nspace
For I = 0 to J-1
Nspace = nspace + "& nbsp ;"
Next
I = 0
Do until adorecordset. EOF
Shtml = shtml _
& "<Div id = '" & parentnode & "_" & I + 1 & "'>" & nspace _
& "<A href = '#'"
If adorecordset. Fields. Item ("children"). value> 0 then
Shtml = shtml & "onclick = 'expandnode (" & parentnode & "_" & I + 1 & "," & adorecordset. fields. item ("ID "). value & ") '> +"
Else
Shtml = shtml & "> -"
End if
Shtml = shtml & "</a>/N" & "<a href = '#'"
If adorecordset. Fields. Item ("children"). value> 0 then
Shtml = shtml & "ondblclick = 'expandnode (" & parentnode & "_" & I + 1 & "," & adorecordset. fields. item ("ID "). value &")'"
End if
Shtml = shtml & ">" & adorecordset. fields. item ("ID "). value & ":" & adorecordset. fields. item ("remark "). value & "</a> </div>"
If adorecordset. Fields. Item ("children"). value> 0 then
Shtml = shtml & "<Div id = '" & parentnode & "_" & I + 1 & "_ 0' style = 'display: none 'loaded = 'no'> "& nspace &" & nbsp; loading... </div>"
End if
I = I + 1
Adorecordset. movenext
Loop
Adorecordset. Close
Set adorecordset = nothing
Adoconnection. Close
Set adoconnection = nothing
'Response. Write shtml
%>
<SCRIPT>
VaR x = eval ('parent. '+' <% = request. querystring ("pnode") & "_ 0" %> ');
X. innerhtml = "<% = shtml %> ";
</SCRIPT>
</Body>
</Html>
Table Structure:
Tree (ID, parentid, remark)