asp动态级联菜单代码

时间:2021-05-28

JS脚本:
<%
dimrs
dimsql
dimcount
dimrs1
dimsql1
sql="select*fromregionorderbyzoneidasc"
setrs=server.createobject("adodb.recordset")
rs.opensql,conn,1,3
%>
<scriptlanguage="JavaScript">
varonecount;
onecount=0;
subcat=newArray();
<%
count=0
dowhilenotrs.eof
%>
subcat[<%=count%>]=newArray("<%=trim(rs("regionname"))%>","<%=trim(rs("zoneid"))%>","<%=trim(rs("regionid"))%>");
<%
count=count+1
rs.movenext
loop
rs.close
setrs=nothing
%>
onecount=<%=count%>;

functionchangelocation(zoneid)
{
document.myform.region.length=0;

varzoneid=zoneid;
vari;
document.myform.region.options[0]=newOption('--地区--','');
for(i=0;i<onecount;i++)
{
if(subcat[i][1]==zoneid)
{
document.myform.region.options[document.myform.region.length]=newOption(subcat[i][0],subcat[i][2]);
}
}

}
</script>

表单内容:
<table>
<form>
<tr>
<td>
<spanclass="STYLE1">*</span>大区:
<selectname="zone"size="1"id="zone"onChange="changelocation(document.myform.zone.options[document.myform.zone.selectedIndex].value)">
<optionvalue=0selected>请选择</option>
<%

sql1="select*frombigzoneorderbyzonenameasc"
setrs1=server.createobject("adodb.recordset")
rs1.opensql1,conn,1,3
%>
<%whilenotrs1.eof%>
<optionvalue="<%=rs1("zoneid")%>"><%=rs1("zonename")%></option>
<%rs1.movenext
wend
rs1.close
setrs1=nothing
%>
</select></td>
<tdwidth="20%"><spanclass="STYLE1">*</span>地区:
<selectname="region"size="1"id="region">
<optionvalue=0selected>请选择</option>
</select>
</tr>
</form>
</table>

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章