ASP三级联动,第三级联动实现,求解
<!--#includefile="fyconn.asp"--><formname="myform"method="post"><%sq="select*fromDepa...
<!--#include file="fyconn.asp" --> <form name="myform" method="post">
<%
sq="select * from Department where Layer=1"
rs.open sq,conn,1,1
%>
<select name="class1" onChange="javascript:changeclass2();changeclass3()">
<option value="" selected>一级部门选择</option>
<% while not rs.eof %>
<option value="<%=rs("DeptID")%>"><%=rs("DeptName")%>
</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>
<input name="price" type="hidden" type="text" id="price">
</form>
<%
sql="select * from Department where Layer=2"
rs.open sql,conn,1,1
num=rs.recordcount
str=""
for i=1 to rs.recordcount
str=str&rs("DeptID1")&"-"&rs("DeptName")&","
if rs.eof then exit for
rs.movenext
next
rs.close
%>
<%
sql="select * from Department where Layer=3"
rs.open sql,conn,1,1
num2=rs.recordcount
str2=""
for i=1 to rs.recordcount
str2=str2&rs("DeptID2")&"-"&rs("DeptName")&","
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]));
document.myform.price.value=document.myform.class1.value
}
}
}
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]));
document.myform.price.value=document.myform.class2.value
}
}
}
</script>
三级部门同表存储,以layer定级,以DeptID1至3标明所属一至三级的上级部门,上程序一二级菜单可以联动,但三级联动不了,也知道问题出在从二级ID确定三级部门列表上,改不好,请高手帮忙,在线等,试好了就给分。
部门表Department结构:DeptID(部门ID) DeptID1 DeptID2 DeptID3(所属一至三级部门的ID) DeptName Layer(部门级别) 展开
<%
sq="select * from Department where Layer=1"
rs.open sq,conn,1,1
%>
<select name="class1" onChange="javascript:changeclass2();changeclass3()">
<option value="" selected>一级部门选择</option>
<% while not rs.eof %>
<option value="<%=rs("DeptID")%>"><%=rs("DeptName")%>
</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>
<input name="price" type="hidden" type="text" id="price">
</form>
<%
sql="select * from Department where Layer=2"
rs.open sql,conn,1,1
num=rs.recordcount
str=""
for i=1 to rs.recordcount
str=str&rs("DeptID1")&"-"&rs("DeptName")&","
if rs.eof then exit for
rs.movenext
next
rs.close
%>
<%
sql="select * from Department where Layer=3"
rs.open sql,conn,1,1
num2=rs.recordcount
str2=""
for i=1 to rs.recordcount
str2=str2&rs("DeptID2")&"-"&rs("DeptName")&","
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]));
document.myform.price.value=document.myform.class1.value
}
}
}
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]));
document.myform.price.value=document.myform.class2.value
}
}
}
</script>
三级部门同表存储,以layer定级,以DeptID1至3标明所属一至三级的上级部门,上程序一二级菜单可以联动,但三级联动不了,也知道问题出在从二级ID确定三级部门列表上,改不好,请高手帮忙,在线等,试好了就给分。
部门表Department结构:DeptID(部门ID) DeptID1 DeptID2 DeptID3(所属一至三级部门的ID) DeptName Layer(部门级别) 展开
3个回答
展开全部
程序看了一下,知道是哪里错了。
告诉你原因,自己改吧,不行在Hi我。
str=str&rs("DeptID1")&"-"&rs("DeptName")&","
没有记录DeptID2,所以你构建的
document.myform.class2.options.add(new Option(ar[i][1], ar[i][1]));
的value=的是你2级部门的DeptName,这里本应该是DeptID2。这句对照一级部门的构建句子就明白了
<option value="<%=rs("DeptID")%>"><%=rs("DeptName")%>
看到了吧,他的value是DeptID,而DeptName是在页面显示的文字内容。联动的关联值是DeptID。
这样就造成你在 changeclass3() 函数的
执行过程中找不到
ar2[i][0] == lid2
等式成立的情况,也就是永不相等。
不懂就Hi我。
告诉你原因,自己改吧,不行在Hi我。
str=str&rs("DeptID1")&"-"&rs("DeptName")&","
没有记录DeptID2,所以你构建的
document.myform.class2.options.add(new Option(ar[i][1], ar[i][1]));
的value=的是你2级部门的DeptName,这里本应该是DeptID2。这句对照一级部门的构建句子就明白了
<option value="<%=rs("DeptID")%>"><%=rs("DeptName")%>
看到了吧,他的value是DeptID,而DeptName是在页面显示的文字内容。联动的关联值是DeptID。
这样就造成你在 changeclass3() 函数的
执行过程中找不到
ar2[i][0] == lid2
等式成立的情况,也就是永不相等。
不懂就Hi我。
Storm代理
2023-08-29 广告
2023-08-29 广告
"StormProxies是全球大数据IP资源服务商,其住宅代理网络由真实的家庭住宅IP组成,可为企业或个人提供满足各种场景的代理产品。点击免费测试(注册即送1G流量)StormProxies有哪些优势?1、IP+端口提取形式,不限带宽,I...
点击进入详情页
本回答由Storm代理提供
展开全部
数据库表
shop_anclass
anclassid
anclass
shop_nclass
nclassid
nclass
anclassid
san
sanid
nclassid
sanname
QQ.ASP
<!--#include file "conn.asp" -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>ASP三级联动菜单代码</title>
<%
set rs=server.createobject("adodb.recordset")
rs.open "select * from shop_nclass order by nclassid ",conn,1,1%>
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
<%
count = 0
do while not rs.eof
%>
subcat[<%=count%>] = new Array("<%= trim(rs("nclass"))%>","<%= rs("anclassid")%>","<%= rs("nclassid")%>");
<%
count = count + 1
rs.movenext
loop
rs.close
%>
onecount=<%=count%>;
function changelocation(locationid)
{
document.bd.nclassid.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.bd.nclassid.options[document.bd.nclassid.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
</script>
<%
set rs2=server.createobject("adodb.recordset")
rs2.open "select * from san order by sanid ",conn,1,1%>
<script language = "JavaScript">
var onecount2;
onecount2=0;
subcat2 = new Array();
<%
count2 = 0
do while not rs2.eof
%>
subcat2[<%=count2%>] = new Array("<%= trim(rs2("sanname"))%>","<%= rs2("nclassid")%>","<%= rs2("sanid")%>");
<%
count2 = count2 + 1
rs2.movenext
loop
rs2.close
%>
onecount2=<%=count2%>;
function changelocation2(locationid)
{
document.bd.sanid.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount2; i++)
{
if (subcat2[i][1] == locationid)
{
document.bd.sanid.options[document.bd.sanid.length] = new Option(subcat2[i][0], subcat2[i][2]);
}
}
}
</script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="8">
<tr>
<td><table width="800" border="0" cellpadding="3" cellspacing="1" bgcolor="#333333">
<tr align="right" bgcolor="#FFFFFF">
<td height="22" colspan="10"><form name="bd" method="post" action="">
<input name="ss" type="hidden" id="ss" value="yes">
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td><%
rs.open "select * from shop_anclass order by anclassid",conn,1,1
if rs.eof and rs.bof then
response.write ""
response.end
else
%>
<select name="anclassid" size="1" id="anclassid" onChange="changelocation(document.bd.anclassid.options[document.bd.anclassid.selectedIndex].value)">
<% dim selclass
selclass=rs("anclassid")
do while not rs.eof
%>
大类<option value="<%=rs("anclassid")%>"><%=trim(rs("anclass"))%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select>
小类
<select name="nclassid" size="1" id="nclassid" onChange="changelocation2(document.bd.nclassid.options[document.bd.nclassid.selectedIndex].value)">
<%
rs.open "select * from shop_nclass where anclassid="&selclass,conn,1,1
do while not rs.eof
%>
<option value="<%=rs("nclassid")%>"><%=trim(rs("nclass"))%></option>
<%
rs.movenext
loop
%>
</select>
<select name="sanid">
<option value="0">请选择三级分类</option>
</select>
第三类名称:<input name="sanname" type="text" id="sanname" size="25"></td>
<td width="57"><input type="submit" name="Submit2" value="添加"></td>
</tr>
</table>
</form></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
修改产品所在的类别
<%
rs.open "select * from shop_anclass order by anclassid",conn,1,1
if rs.eof and rs.bof then
response.write ""
response.end
else
%>
<select name="anclassid" size="1" id="anclassid" onChange="changelocation(document.bd.anclassid.options[document.bd.anclassid.selectedIndex].value)">
<option value="<%=anclassid%>"><%=anclass%></option>
<% dim selclass
selclass=rs("anclassid")
do while not rs.eof
%>
大类<option value="<%=rs("anclassid")%>"><%=trim(rs("anclass"))%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select>
小类
<select name="nclassid" size="1" id="nclassid" onChange="changelocation2(document.bd.nclassid.options[document.bd.nclassid.selectedIndex].value)">
<option value="<%=nclassid%>"><%=nclass%></option>
<%
rs.open "select * from shop_nclass where anclassid="&selclass,conn,1,1
do while not rs.eof
%>
<option value="<%=rs("nclassid")%>"><%=trim(rs("nclass"))%></option>
<%
rs.movenext
loop
%>
</select>
<select name="sanid">
<option value="<%=sanid%>"><%=sanname%></option>
</select>
shop_anclass
anclassid
anclass
shop_nclass
nclassid
nclass
anclassid
san
sanid
nclassid
sanname
QQ.ASP
<!--#include file "conn.asp" -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>ASP三级联动菜单代码</title>
<%
set rs=server.createobject("adodb.recordset")
rs.open "select * from shop_nclass order by nclassid ",conn,1,1%>
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
<%
count = 0
do while not rs.eof
%>
subcat[<%=count%>] = new Array("<%= trim(rs("nclass"))%>","<%= rs("anclassid")%>","<%= rs("nclassid")%>");
<%
count = count + 1
rs.movenext
loop
rs.close
%>
onecount=<%=count%>;
function changelocation(locationid)
{
document.bd.nclassid.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.bd.nclassid.options[document.bd.nclassid.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
</script>
<%
set rs2=server.createobject("adodb.recordset")
rs2.open "select * from san order by sanid ",conn,1,1%>
<script language = "JavaScript">
var onecount2;
onecount2=0;
subcat2 = new Array();
<%
count2 = 0
do while not rs2.eof
%>
subcat2[<%=count2%>] = new Array("<%= trim(rs2("sanname"))%>","<%= rs2("nclassid")%>","<%= rs2("sanid")%>");
<%
count2 = count2 + 1
rs2.movenext
loop
rs2.close
%>
onecount2=<%=count2%>;
function changelocation2(locationid)
{
document.bd.sanid.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount2; i++)
{
if (subcat2[i][1] == locationid)
{
document.bd.sanid.options[document.bd.sanid.length] = new Option(subcat2[i][0], subcat2[i][2]);
}
}
}
</script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="8">
<tr>
<td><table width="800" border="0" cellpadding="3" cellspacing="1" bgcolor="#333333">
<tr align="right" bgcolor="#FFFFFF">
<td height="22" colspan="10"><form name="bd" method="post" action="">
<input name="ss" type="hidden" id="ss" value="yes">
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td><%
rs.open "select * from shop_anclass order by anclassid",conn,1,1
if rs.eof and rs.bof then
response.write ""
response.end
else
%>
<select name="anclassid" size="1" id="anclassid" onChange="changelocation(document.bd.anclassid.options[document.bd.anclassid.selectedIndex].value)">
<% dim selclass
selclass=rs("anclassid")
do while not rs.eof
%>
大类<option value="<%=rs("anclassid")%>"><%=trim(rs("anclass"))%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select>
小类
<select name="nclassid" size="1" id="nclassid" onChange="changelocation2(document.bd.nclassid.options[document.bd.nclassid.selectedIndex].value)">
<%
rs.open "select * from shop_nclass where anclassid="&selclass,conn,1,1
do while not rs.eof
%>
<option value="<%=rs("nclassid")%>"><%=trim(rs("nclass"))%></option>
<%
rs.movenext
loop
%>
</select>
<select name="sanid">
<option value="0">请选择三级分类</option>
</select>
第三类名称:<input name="sanname" type="text" id="sanname" size="25"></td>
<td width="57"><input type="submit" name="Submit2" value="添加"></td>
</tr>
</table>
</form></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
修改产品所在的类别
<%
rs.open "select * from shop_anclass order by anclassid",conn,1,1
if rs.eof and rs.bof then
response.write ""
response.end
else
%>
<select name="anclassid" size="1" id="anclassid" onChange="changelocation(document.bd.anclassid.options[document.bd.anclassid.selectedIndex].value)">
<option value="<%=anclassid%>"><%=anclass%></option>
<% dim selclass
selclass=rs("anclassid")
do while not rs.eof
%>
大类<option value="<%=rs("anclassid")%>"><%=trim(rs("anclass"))%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select>
小类
<select name="nclassid" size="1" id="nclassid" onChange="changelocation2(document.bd.nclassid.options[document.bd.nclassid.selectedIndex].value)">
<option value="<%=nclassid%>"><%=nclass%></option>
<%
rs.open "select * from shop_nclass where anclassid="&selclass,conn,1,1
do while not rs.eof
%>
<option value="<%=rs("nclassid")%>"><%=trim(rs("nclass"))%></option>
<%
rs.movenext
loop
%>
</select>
<select name="sanid">
<option value="<%=sanid%>"><%=sanname%></option>
</select>
参考资料: http://hi.baidu.com/%B1%B1%B7%BD%B2%CB%B2%CB/blog/item/bf89da24883e926834a80ff4.html
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
为什么不用ajax联动呢/?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询