ASP三级联动问题 30
<html><head><title>js动态三级联动下拉表单试验</title><!--=======打开数据库======--><%SetConn=Server.Cr...
<html>
<head>
<title>js动态三级联动下拉表单试验</title>
<!--=======打开数据库======-->
<%
Set Conn = Server.CreateObject("ADODB.Connection")
StrCnn = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("2009-11-8.mdb") & ";"
Conn.Open StrCnn
%>
</head>
<body>
<form name="myform" method="get">
<%
set rs=server.CreateObject("adodb.recordset")
sq="select * from line_class"
rs.open sq,conn,1,1
%>
<select name="class1" onChange="changeclass2();changeclass3()">
<option value="" selected>选择一级目录</option>
<%
while not rs.eof
%>
<option value="<%=rs("id")%>"><%=rs("name")%>
</option>
<%
rs.movenext
wend
rs.close
%>
</select>
<select name="class2" onChange="changeclass3()">
<option value="" selected>选择二级目录</option>
</select>
<select name="class3">
<option value="" selected>选择三级目录</option>
</select>
<label>
<input type="submit" name="button" id="button" value="提交">
</label>
</form>
<%
sql="select * from line_class2"
rs.open sql,conn,1,1
num=rs.recordcount
str=""
for i=1 to rs.recordcount
str=str&rs("classid1")&"-"&rs("name1")&","
if rs.eof then exit for
rs.movenext
next
rs.close
%>
<%
sql="select * from line_class3"
rs.open sql,conn,1,1
num2=rs.recordcount
str2=""
for i=1 to rs.recordcount
str2=str2&rs("classid2")&"-"&rs("name2")&","
if rs.eof then exit for
rs.movenext
next
rs.close
%>
<!--下面是实现动态改变下一级菜单的脚本代码-->
<script LANGUAGE="javascript">
arr="<%=str%>".split(",");
a=arr.length
ar=new Array()
for (i=0;i<a;i++){
ar[i]=arr[i].split("-");
}
onecount=ar.length;
arr2="<%=str2%>".split(",");
a2=arr2.length
ar2=new Array()
for (i=0;i<a2;i++){
ar2[i]=arr2[i].split("-");
}
onecount2=ar2.length;
function changeclass2() {
document.myform.class2.length=0
lid=myform.class1.value;
for (i=0;i<onecount;i++) {
if (ar[i][0] == lid) {
document.myform.class2.options.add(new Option(ar[i][1], ar[i][1]));
}
}
}
function changeclass3() {
document.myform.class3.length=0
lid2=myform.class2.value;
for (i=0;i<onecount2;i++) {
if (ar2[i][0] == lid2) {
document.myform.class3.options.add(new Option(ar2[i][1], ar2[i][1]));
}
}
}
</script>
</body>
</html>
这是代码,数据库三个表,line_class,line_class2,lin_class3
现在就是想让line_class2,line_class3的classid和line_class中的ID关联,
后两个和前一个关联,line_class2和line_class3中都有classid,这个classid和line_class中的ID对应 展开
<head>
<title>js动态三级联动下拉表单试验</title>
<!--=======打开数据库======-->
<%
Set Conn = Server.CreateObject("ADODB.Connection")
StrCnn = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("2009-11-8.mdb") & ";"
Conn.Open StrCnn
%>
</head>
<body>
<form name="myform" method="get">
<%
set rs=server.CreateObject("adodb.recordset")
sq="select * from line_class"
rs.open sq,conn,1,1
%>
<select name="class1" onChange="changeclass2();changeclass3()">
<option value="" selected>选择一级目录</option>
<%
while not rs.eof
%>
<option value="<%=rs("id")%>"><%=rs("name")%>
</option>
<%
rs.movenext
wend
rs.close
%>
</select>
<select name="class2" onChange="changeclass3()">
<option value="" selected>选择二级目录</option>
</select>
<select name="class3">
<option value="" selected>选择三级目录</option>
</select>
<label>
<input type="submit" name="button" id="button" value="提交">
</label>
</form>
<%
sql="select * from line_class2"
rs.open sql,conn,1,1
num=rs.recordcount
str=""
for i=1 to rs.recordcount
str=str&rs("classid1")&"-"&rs("name1")&","
if rs.eof then exit for
rs.movenext
next
rs.close
%>
<%
sql="select * from line_class3"
rs.open sql,conn,1,1
num2=rs.recordcount
str2=""
for i=1 to rs.recordcount
str2=str2&rs("classid2")&"-"&rs("name2")&","
if rs.eof then exit for
rs.movenext
next
rs.close
%>
<!--下面是实现动态改变下一级菜单的脚本代码-->
<script LANGUAGE="javascript">
arr="<%=str%>".split(",");
a=arr.length
ar=new Array()
for (i=0;i<a;i++){
ar[i]=arr[i].split("-");
}
onecount=ar.length;
arr2="<%=str2%>".split(",");
a2=arr2.length
ar2=new Array()
for (i=0;i<a2;i++){
ar2[i]=arr2[i].split("-");
}
onecount2=ar2.length;
function changeclass2() {
document.myform.class2.length=0
lid=myform.class1.value;
for (i=0;i<onecount;i++) {
if (ar[i][0] == lid) {
document.myform.class2.options.add(new Option(ar[i][1], ar[i][1]));
}
}
}
function changeclass3() {
document.myform.class3.length=0
lid2=myform.class2.value;
for (i=0;i<onecount2;i++) {
if (ar2[i][0] == lid2) {
document.myform.class3.options.add(new Option(ar2[i][1], ar2[i][1]));
}
}
}
</script>
</body>
</html>
这是代码,数据库三个表,line_class,line_class2,lin_class3
现在就是想让line_class2,line_class3的classid和line_class中的ID关联,
后两个和前一个关联,line_class2和line_class3中都有classid,这个classid和line_class中的ID对应 展开
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家提供动态代理服务器服务的企业,旨在帮助用户更好地管理网络访问和安全。以下是一些关于StormProxies的IP动态代理服务的特点:1. 高匿名性:StormProxies的动态代理服务器具有高匿名性,可以有效...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询