<%
Dim Con1,Rs
Dim SQL,DSN
Dim Array1()
Set Con1=server.CreateObject("adodb.connection")
Set Rs=server.CreateObject("adodb.recordset")
DSN="driver={Microsoft Access Driver (*.mdb)};dbq=" &server.MapPath("User.mdb")
Con1.Open DSN
SQL="select * from Company order by CompanyID"
Rs.Open SQL,Con1,3,2
Rs.MoveFirst
ReDim Array1(Rs.RecordCount-1)
%>
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="82">
<select id="select1" name="select1">
<option selected value="select<%=Rs("CompanyCode")%>"><%=Rs("CompanyName")%></option>
<%
'Array1数组存放CompanyCode字段值
Array1(0)=Rs("CompanyCode")
Rs.MoveNext
Dim i
For i=1 To Rs.RecordCount-1
%>
<option value="select<%=Rs("CompanyCode")%>"><%=Rs("CompanyName")%></option>
<%
Array1(i)=Rs("CompanyCode")
Rs.MoveNext
Next
%>
</select>
<%
Rs.Close
%>
</td>
<td width="191">
<%
'将Department中对应数组Array1中的每个元素取出来
For i=0 To UBound(Array1)
SQL="select * from Department where DepartmentCode like '"&Array1(i)&"%'"
Rs.Open SQL,Con1,3,2
If Rs.RecordCount > 0 Then
Rs.MoveFirst
%>
<select id="select<%=Array1(i)%>" style="display='none'" name="select<%=Array1(i)%>">
<%Do While Not Rs.Eof%>
<option value="<%=Rs("DepartmentName")%>"><%=Rs("DepartmentName")%></option>
<%
Rs.MoveNext
Loop
%>
</select>
<%
End If
Rs.Close
Next
%>
</td>
</tr>
</table>
<script language="vbscript">
<!--
Dim obj,lastObj
lastObj="select01"
obj="select01"
Window.execScript "select01.style.display='block'","vbs"
Sub select1_onchange
obj=select1.value
If obj <> lastObj And IsObject(eval(obj)) Then
Window.execScript obj & ".style.display='block'","vbs"
Window.execScript lastObj &".style.display='none'","vbs"
Window.execScript "Department="&obj&".value","vbs"
lastObj=select1.value
End If
End Sub
-->
</script>
window对象execScript实现的级联下拉列表的核心代码
最新推荐文章于 2023-01-31 21:54:56 发布