Similar to the implementation of the left navigation tree of msdn csdn! [JavaScript + Asp]

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.