标题:ASP+JS四级联动下拉菜单(修改上次的缺陷)
只看楼主
smh4037
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2008-6-21
 问题点数:0 回复次数:0 
ASP+JS四级联动下拉菜单(修改上次的缺陷)
<style type="text/css">
<!--
body,td,th {
    font-size: 12px;
}
-->
</style>

<!--#include file="conn.asp"-->
<%
StartTime = Timer()
Str    = ""
roota  = "root"
Set rs = Server.Createobject("ADODB.RecordSet")
Sql    = "select * From MT_sshqdei"
rs.Open Sql,conn,1,1
I      = 0
Do While Not rs.Eof
Str    = Str &"array["&I&"]=new Array('"&rs("deiname")&"','"&roota&"','"&rs("deiname")&"');"&chr(13) '地域
I      = I + 1
        rootb   = rs("deiname")
        Set rs1 = Server.Createobject("ADODB.RecordSet")
        Sql     = "select * From MT_province where deiid="& rs("id")
        rs1.Open Sql,conn,1,1
        Do While Not rs1.Eof
        Str     = Str &"array["&I&"]=new Array('"&rs1("shengname")&"','"&rootb&"','"&rs1("shengname")&"');"&chr(13)'省级
        I       = I + 1
rootc   = rs1("shengname")
Set rs2 = Server.Createobject("ADODB.RecordSet")
Sql     = "select * From MT_city where shengid="& rs1("id")
rs2.Open Sql,conn,1,1
Do While Not rs2.Eof
Str     = Str &"array["&I&"]=new Array('"&rs2("shiname")&"','"&rootc&"','"&rs2("shiname")&"');"&chr(13)'市级
I       = I + 1
        rootd   = rs2("shiname")
        Set rs3 = Server.Createobject("ADODB.RecordSet")
        Sql     = "select * From MT_xiang where shiid="& rs2("id")
        rs3.Open Sql,conn,1,1
        Do While Not rs3.Eof
        Str     = Str &"array["&I&"]=new Array('"&rs3("xiangname")&"','"&rootd&"','"&rs3("xiangname")&"');"&chr(13)'县级
        I       = I + 1
        rs3.MoveNext
        Loop
        rs3.Close
        Set rs3 = Nothing
rs2.MoveNext
Loop
rs2.Close
Set rs2 = Nothing
        rs1.MoveNext
        Loop
        rs1.Close
        Set rs1 = Nothing
rs.MoveNext
Loop
rs.Close
Set rs = Nothing

Set FSO = Server.Createobject("scripting.filesystemobject")
Set fil2= FSO.CreateTextFile(server.mappath("sshqjs.html"),2,True)
fil2.Write "<select id=""s1"" name=""s1""></select><select id=""s2"" name=""s2""></select><select id=""s3"" name=""s3""></select><select id=""s4"" name=""s4""></select>" & vbNewLine
fil2.Write "<script language=""JavaScript"">" & vbNewLine
fil2.Write "<!--" & vbNewLine
fil2.Write "function LianDong(arr, sel)" & vbNewLine
fil2.Write "{" & vbNewLine
fil2.Write "var me = this;" & vbNewLine
fil2.Write "this.$ = function(o)" & vbNewLine
fil2.Write "{" & vbNewLine
fil2.Write "return document.getElementById(o);" & vbNewLine
fil2.Write "}" & vbNewLine
fil2.Write "this.sub = function (i, pid)" & vbNewLine
fil2.Write "{" & vbNewLine
fil2.Write "for (var j=i+1; j<sel.length; j++)" & vbNewLine
fil2.Write "{" & vbNewLine
fil2.Write "me.$(sel[j]).length = 0;" & vbNewLine
fil2.Write "me.$(sel[j]).options[0] = new Option(""请选择"", """");" & vbNewLine
fil2.Write "}" & vbNewLine
fil2.Write "for ( var j = 0; j < arr.length; j++)" & vbNewLine
fil2.Write "{" & vbNewLine
fil2.Write "if (arr[j][1] == pid)" & vbNewLine
fil2.Write "{" & vbNewLine
fil2.Write "me.$(sel[i+1]).options[me.$(sel[i+1]).length] = new Option(arr[j][2], arr[j][0]);" & vbNewLine
fil2.Write "}" & vbNewLine
fil2.Write "}" & vbNewLine
fil2.Write "}" & vbNewLine
fil2.Write "this.init = function()" & vbNewLine
fil2.Write "{" & vbNewLine
fil2.Write "me.sub(-1,""root"");" & vbNewLine
fil2.Write "for (var i=0; i<sel.length-1; i++)" & vbNewLine
fil2.Write "{" & vbNewLine
fil2.Write "me.$(sel[i]).onchange = function()" & vbNewLine
fil2.Write "{" & vbNewLine
fil2.Write "var i;" & vbNewLine
fil2.Write "for (i=0; me.$(sel[i])!=this; i++);" & vbNewLine
fil2.Write "me.sub(i, me.$(sel[i]).value);" & vbNewLine
fil2.Write "}" & vbNewLine
fil2.Write "}" & vbNewLine
fil2.Write "}" & vbNewLine
fil2.Write "this.init();" & vbNewLine
fil2.Write "}" & vbNewLine
fil2.Write "var array=new Array();" & vbNewLine
fil2.Write Str
fil2.Write "var select = new Array(""s1"",""s2"",""s3"",""s4"");" & vbNewLine
fil2.Write "var liandong=new LianDong(array, select)" & vbNewLine
fil2.Write "//-->" & vbNewLine
fil2.Write "</script>" & vbNewLine
Set FSO = Nothing
EndTime = Timer()
CountTime = EndTime - StartTime
Response.Write "文件生成完毕......<P>耗时:<Font color=red>0"&CountTime&"</font>毫秒"
%>
搜索更多相关主题的帖子: 四级 ASP 缺陷 菜单 
2008-06-26 22:18



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-221478-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.157491 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved