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>毫秒"
%>