一段生成treeview的js代码,希望对大家有用,有演示

发表于:2007-06-30来源:作者:点击数: 标签:
一段生成treeview的js代码 演示:http://www.zwtd.com/2/treeview/treeview.asp html head titleASP TreeView Exemple/title meta name=author content=Simon La Rochelle meta name=description content=This is an easy way to make a vb -like TreeView in
一段生成treeview的js代码
演示:http://www.zwtd.com/2/treeview/treeview.asp
<html>
<head>
<title>ASP TreeView Exemple</title>
<meta name="author" content="Simon La Rochelle">
<meta name="description" content="This is an easy way to make a vb-like TreeView in ASP">

<script language=@#javascript@#>

function ToggleDisplay(oButton, oItems) {

    if ((oItems.style.display == "") || (oItems.style.display == "none")) {
        oItems.style.display = "block";
        oButton.src = "minus.gif";
    }    else {
        oItems.style.display = "none";
        oButton.src = "plus.gif";
    }

    return false;

}

function HideDisplay(oItems) {

    oItems.style.display = "none";

}

function ShowDisplay(oItems) {

    oItems.style.display = "block";

}

</script>

</head>

<body bgcolor=@##FFFFFF@#>
<form action=@#TreeView.asp@# method=@#post@#>

<%

@#HERE@#S THE FIRST EXEMPLE (without checkboxes and links)
WriteHead "MyTreeView",1,"Exemple1",0,True,False,"",False
    WriteHead "MyTreeView",2,"Child1",1,True,False,"",False
        WriteHead "MyTreeView",3,"Child1-A",2,False,False,"",False
        WriteFoot
        WriteHead "MyTreeView",4,"Child1-B",2,False,False,"",False
        WriteFoot
        WriteHead "MyTreeView",5,"Child1-C",2,False,False,"",False
        WriteFoot
        WriteHead "MyTreeView",6,"Child1-D",2,False,False,"",False
        WriteFoot
    WriteFoot
    WriteHead "MyTreeView",7,"Child2",1,False,False,"",False
    WriteFoot
    WriteHead "MyTreeView",8,"Child3",1,False,False,"",False
    WriteFoot
    WriteHead "MyTreeView",9,"Child4",1,False,False,"",False
    WriteFoot
    WriteHead "MyTreeView",10,"Child5",1,False,False,"",False
    WriteFoot
WriteFoot

@#Response.Write "<p>"

@#HERE@#S THE SECOND EXEMPLE (with checkboxes)
WriteHead "My2TreeView",1,"Exemple2",0,True,False,"",False
    WriteHead "My2TreeView",2,"Child1",1,True,False,"",False
        WriteHead "My2TreeView",3,"Child1-A",2,False,True,"",False
        WriteFoot
        WriteHead "My2TreeView",4,"Child1-B",2,False,True,"",False
        WriteFoot
        WriteHead "My2TreeView",5,"Child1-C",2,False,True,"",False
        WriteFoot
        WriteHead "My2TreeView",6,"Child1-D",2,False,True,"",False
        WriteFoot
    WriteFoot
    WriteHead "My2TreeView",7,"Child2",1,False,True,"",False
    WriteFoot
    WriteHead "My2TreeView",8,"Child3",1,False,True,"",False
    WriteFoot
    WriteHead "My2TreeView",9,"Child4",1,False,True,"",False
    WriteFoot
    WriteHead "My2TreeView",10,"Child5",1,False,True,"",False
    WriteFoot
WriteFoot

@#Response.Write "<p>"

@#HERE@#S THE THIRD EXEMPLE (with links)
WriteHead "My3TreeView",1,"Development Sites",0,True,False,"",true
    WriteHead "My3TreeView",2,"Planet Source Code",1,True,False,"http://www.planetsourcecode.com",False
        WriteHead "My3TreeView",3,"Visual Basic",2,False,False,"http://www.planetsourcecode.com/xq/ASP/lngWId.1/qx/vb/default.htm",False
        WriteFoot
        WriteHead "My3TreeView",4,"Java / Javascript",2,False,False,"http://www.planetsourcecode.com/xq/ASP/lngWId.2/qx/vb/default.htm",False
        WriteFoot
        WriteHead "My3TreeView",5,"C / C++",2,False,False,"http://www.planetsourcecode.com/xq/ASP/lngWId.3/qx/vb/default.htm",False
        WriteFoot
        WriteHead "My3TreeView",6,"ASP / VbScript",2,False,False,"http://www.planetsourcecode.com/xq/ASP/lngWId.4/qx/vb/default.htm",False
        WriteFoot
        WriteHead "My3TreeView",7,"SQL",2,False,False,"http://www.planetsourcecode.com/xq/ASP/lngWId.5/qx/vb/default.htm",False
        WriteFoot
        WriteHead "My3TreeView",8,"Perl",2,False,False,"http://www.planetsourcecode.com/xq/ASP/lngWId.6/qx/vb/default.htm",False
        WriteFoot
        WriteHead "My3TreeView",9,"Delphi",2,False,False,"http://www.planetsourcecode.com/xq/ASP/lngWId.7/qx/vb/default.htm",False
        WriteFoot
        WriteHead "My3TreeView",10,"PHP",2,False,False,"http://www.planetsourcecode.com/xq/ASP/lngWId.8/qx/vb/default.htm",False
        WriteFoot
    WriteFoot
    WriteHead "My3TreeView",11,"DevX",1,False,False,"http://www.devx.com",False
    WriteFoot
    WriteHead "My3TreeView",12,"MSDN",1,False,False,"http://msdn.microsoft.com",False
    WriteFoot
    WriteHead "My3TreeView",13,"4GuysFromRolla",1,False,False,"http://www.4guysfromrolla.com",False
    WriteFoot
    WriteHead "My3TreeView",14,"LearnASP",1,False,False,"http://www.learnasp.com",False
    WriteFoot
WriteFoot

%>

</form>
</body>
</html>

<%

@#*********************************
@#TREEVIEW SUBS
@#*********************************

Sub WriteHead(TreeName,ItemID,ItemName,Level,IsParent,UseCheckBox,MyLink,IsOpn)

    Dim IsIE @#as boolean
    
    IsIE = (InStr(request.servervariables("HTTP_USER_AGENT"), "MSIE") > 0)

    @#Spacing depends on what level you@#re at
    Select Case Level
        Case 1 : Response.Write "<IMG SRC=@#dot1.gif@# BORDER=0 ALT=@#@#>"
        Case 2 : Response.Write "<IMG SRC=@#t_dot.gif@# WIDTH=36 HEIGHT=18 BORDER=0 ALT=@#@#><IMG SRC=@#dot1.gif@# BORDER=0 ALT=@#@#>"
        Case 3 : Response.Write "<IMG SRC=@#t_dot.gif@# WIDTH=72 HEIGHT=18 BORDER=0 ALT=@#@#><IMG SRC=@#dot1.gif@# BORDER=0 ALT=@#@#>"
        Case 4 : Response.Write "<IMG SRC=@#t_dot.gif@# WIDTH=108 HEIGHT=18 BORDER=0 ALT=@#@#><IMG SRC=@#dot1.gif@# BORDER=0 ALT=@#@#>"
        Case 5 : Response.Write "<IMG SRC=@#t_dot.gif@# WIDTH=144 HEIGHT=18 BORDER=0 ALT=@#@#><IMG SRC=@#dot1.gif@# BORDER=0 ALT=@#@#>"
        Case 6 : Response.Write "<IMG SRC=@#t_dot.gif@# WIDTH=180 HEIGHT=18 BORDER=0 ALT=@#@#><IMG SRC=@#dot1.gif@# BORDER=0 ALT=@#@#>"
        Case 7 : Response.Write "<IMG SRC=@#t_dot.gif@# WIDTH=216 HEIGHT=18 BORDER=0 ALT=@#@#><IMG SRC=@#dot1.gif@# BORDER=0 ALT=@#@#>"
        Case 8 : Response.Write "<IMG SRC=@#t_dot.gif@# WIDTH=252 HEIGHT=18 BORDER=0 ALT=@#@#><IMG SRC=@#dot1.gif@# BORDER=0 ALT=@#@#>"
        Case 9 : Response.Write "<IMG SRC=@#t_dot.gif@# WIDTH=288 HEIGHT=18 BORDER=0 ALT=@#@#><IMG SRC=@#dot1.gif@# BORDER=0 ALT=@#@#>"
        Case 10 : Response.Write "<IMG SRC=@#t_dot.gif@# WIDTH=324 HEIGHT=18 BORDER=0 ALT=@#@#><IMG SRC=@#dot1.gif@# BORDER=0 ALT=@#@#>"
    End Select

    @#If IsParent then put a plus sign else put a blank space
    If IsParent then
        @#JsCode only if isIE
        If isIE then
            If IsOpn then
                Response.Write "<IMG SRC=@#minus.gif@# WIDTH=12 HEIGHT=10 ID=@#" & TreeName & ItemID & "Btn@# ONCLICK=@#javascript:ToggleDisplay(" & TreeName & ItemID & "Btn, " & TreeName & ItemID & "chlds);@# ALT BORDER=@#0@#>"
            Else
                Response.Write "<IMG SRC=@#plus.gif@# WIDTH=12 HEIGHT=10 ID=@#" & TreeName & ItemID & "Btn@# ONCLICK=@#javascript:ToggleDisplay(" & TreeName & ItemID & "Btn, " & TreeName & ItemID & "chlds);@# ALT BORDER=@#0@#>"
            End If
        Else
            If IsOpn then
                Response.Write "<IMG SRC=@#minus.gif@# WIDTH=12 HEIGHT=10 ID=@#" & TreeName & ItemID & "Btn@# ALT BORDER=@#0@#>"
            Else
                Response.Write "<IMG SRC=@#plus.gif@# WIDTH=12 HEIGHT=10 ID=@#" & TreeName & ItemID & "Btn@# ALT BORDER=@#0@#>"
            End if
        End If    
    Else
        If Level = 0 then
            Response.Write "<IMG SRC=@#nosign2.gif@# WIDTH=12 HEIGHT=10 ALT BORDER=@#0@#>"
        Else
            Response.Write "<IMG SRC=@#nosign.gif@# WIDTH=12 HEIGHT=10 ALT BORDER=@#0@#>"
        End If
    End if
    
    @#If UseCheckBox then show a checkbox else add space
    If UseCheckBox then
        Response.Write "<INPUT TYPE=@#checkbox@# NAME=@#" & TreeName &"chk@# VALUE=@#" & ItemID & "@#>"
    Else
        Response.Write "<img src=@#t_dot.gif@# WIDTH=4 HEIGHT=18 BORDER=0 ALT=@#@#>"
    End If
        
    Response.Write "<font face=@#Verdana,Arial,Helvetica@# size=@#2@# color=@##333399@#>"
    
    @#If MyLink = "" then do not use link
    If MyLink = "" then
        @#If first Level, use bold
        If Level = 0 then Response.Write "<b>" & ItemName & "</b>" else Response.Write ItemName
    Else
        @#If first Level, use bold
        If Level = 0 then Response.Write "<b><a href=@#" & MyLink & "@#><font color=@##333399@#>" & ItemName & "</a></b>" else Response.Write "<a href=@#" & MyLink & "@#><font color=@##333399@#>" & ItemName & "</a>"
    End If

    Response.Write "</font>"
    Response.Write "<br>"
    
    @#Always add DIV because WriteFoot() will close it
    Response.Write "<div ID=@#" & TreeName & ItemID & "chlds@#>"
    
    @#JsCode only if IsIE and if the section is not open
    If IsIE then
        If IsOpn then
            Response.Write "<script language=@#javascript@#>ShowDisplay(" & TreeName & ItemID & "chlds);</script>"
        Else
            Response.Write "<script language=@#javascript@#>HideDisplay(" & TreeName & ItemID & "chlds);</script>"
        End If
    End If

End Sub

Sub WriteFoot()

    Response.Write "</div>"

End Sub

%>

原文转自:http://www.ltesting.net