求助:三级联动读取数据库里面的信息,出现问题周六周日在线求解!谢谢

luchuguo 2009-11-21 11:28:22
我已经做好显示首页:index.asp
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>分级目录模块</title>
</head>
<script>
function showObj(str,imgid) {
divObj=eval(str);
imgObj=eval(imgid);
if (divObj.style.display=="none") {
imgObj.src="img/open.gif";
divObj.style.display="inline";
}
else {
imgObj.src="img/plus.gif";
divObj.style.display="none";
}

}
</script>
<body>
<%
call init()

Sub init()
call Generate("__")
End Sub
'生成文档节点
Sub WriteDoc(layer,title,Content)
For i=1 To len(layer)
Response.Write(" ")
Next
Response.write("<a href="&Content&" >"&title&"</a><br>")
End Sub

'生成文档节点
Sub WriteNode (layer,title)
For i=1 To len(layer)
Response.Write(" ")
Next
Response.write("<img id=img"&layer&" src='img/plus.gif' border=0>"&_
"<a href='#' onclick=showObj('id"&layer&"','img"&layer&_
"')>"&title&" </a><br>")
Response.write("<div id=id"&layer&" style='display:none'>")


End Sub

Sub Generate (layer)
Dim parent
If layer="__" Then
parent="__"
Else
parent=layer
End If
Set Conn=Server.Createobject("Adodb.Connection")
Conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;"&_
"Data Source="&Server.MapPath("user.mdb")
Conn.Open
Set rs=Server.Createobject("Adodb.Recordset")
Sql="Select * from LayerST where IsDisp='1' and Layer Like '"&layer&"'"

rs.Open Sql,Conn,1,1
do while rs.EOF=False
If rs("Type")="1" Then
call WriteNode(rs("Layer"),rs("Title"))
call Generate (rs("Layer")&"__")
Response.write("</div>")
Else
call WriteDoc(rs("Layer"),rs("Title"),rs("Content") )
End If
rs.movenext
loop

rs.close
Conn.close

End Sub
%>
</body>

</html>



数据库为user.mdb表名LayerST的结构如图1:


我需要做效果图2:

,要求粮油一级分类 粮食二级分类 玉米三级分类,且均是从数据库中读取,
演示网址http://www.blueidea.com/tech/web/2006/3368.asp
...全文
82 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
luchuguo 2009-12-16
  • 打赏
  • 举报
回复
function changeselect1(locationid)
{
document.form1.s2.length = 0;
document.form1.s2.options[0] = new Option('==请选择==','');
document.form1.s3.length = 0;
document.form1.s3.options[0] = new Option('==请选择==','');
for (i=0; i <subval2.length; i++)
{
if (subval2[i][0] == locationid)
{ document.form1.s2.options[document.form1.s2.length] = new Option(subval2[i][2],subval2[i][1]); }
}
}

function changeselect2(locationid)
{
document.form1.s3.length = 0;
document.form1.s3.options[0] = new Option('==请选择==','');
for (i=0; i <subval3.length; i++)
{
if (subval3[i][0] == locationid)
{ document.form1.s3.options[document.form1.s3.length] = new Option(subval3[i][2],subval3[i][1]); }
}
}
这部分是主要做联动的,但是s1的value可以传到后台,但s2和s3的值不能,后台的值都是null
lzp4881 2009-11-21
  • 打赏
  • 举报
回复
<!--#include file="inc/conn.asp" -->

<script language="JavaScript" >
<%
Dim counts,rs,sql
sql = "select * from table1 where len(layer)=6"
set rs = conn.execute(sql)
%>
var subval2 = new Array();
//数组结构:一级根值,二级根值,二级显示值
<%
counts = 0
do while not rs.eof
%>
subval2[<%=counts%>] = new Array('<%=left(rs("layer"),4)%>','<%=left(rs("layer"),6)%>','<%=rs("title")%>')
<%
counts = counts + 1
rs.movenext
loop
rs.close
%>

<%
'三级数据保存到数组
sql="select * from table1 where len(layer)=8"
set rs = conn.execute(sql)
%>
var subval3 = new Array();
//数组结构:二级根值,三级根值,三级显示值
<%
counts = 0
do while not rs.eof
%>
subval3[<%=counts%>] = new Array('<%=left(rs("layer"),6)%>','<%=rs("layer")%>','<%=rs("title")%>')
<%
counts = counts + 1
rs.movenext
loop
rs.close
%>

function changeselect1(locationid)
{
document.form1.s2.length = 0;
document.form1.s2.options[0] = new Option('==请选择==','');
document.form1.s3.length = 0;
document.form1.s3.options[0] = new Option('==请选择==','');
for (i=0; i<subval2.length; i++)
{
if (subval2[i][0] == locationid)
{ document.form1.s2.options[document.form1.s2.length] = new Option(subval2[i][2],subval2[i][1]); }
}
}

function changeselect2(locationid)
{
document.form1.s3.length = 0;
document.form1.s3.options[0] = new Option('==请选择==','');
for (i=0; i<subval3.length; i++)
{
if (subval3[i][0] == locationid)
{ document.form1.s3.options[document.form1.s3.length] = new Option(subval3[i][2],subval3[i][1]); }
}
}

</script>

<form name="form1" method="post" action="test1.asp" >

三级联动:
<%
sql="select * from table1 where len(layer)=4"
set rs = conn.execute(sql)
%>
<select name="s1" onChange="changeselect1(this.value)" >
<option> ==请选择==</option>
<%
counts = 0
do while not rs.eof
response.write"<option value='" & rs("layer")& "'>" & rs("title")& "</option> "
counts = counts + 1
rs.movenext
loop
rs.close
%>
</select>

<select name="s2" onChange="changeselect2(this.value)" >
<option> ==请选择==</option>
</select>

<select name="s3" >
<option> ==请选择==</option>
</select>
<input type="submit" name="Submit" value="提交" >

</form>
sy_binbin 2009-11-21
  • 打赏
  • 举报
回复
三級聯動問題!!
我BLOG裏有個二級聯動的,你去看看吧!原理都一樣!!
luchuguo 2009-11-21
  • 打赏
  • 举报
回复
function changeselect1(locationid)
{
document.form1.s2.length = 0;
document.form1.s2.options[0] = new Option('==请选择==','');
document.form1.s3.length = 0;
document.form1.s3.options[0] = new Option('==请选择==','');
for (i=0; i <subval2.length; i++)
{
if (subval2[i][0] == locationid)
{ document.form1.s2.options[document.form1.s2.length] = new Option(subval2[i][2],subval2[i][1]); }
}
}

function changeselect2(locationid)
{
document.form1.s3.length = 0;
document.form1.s3.options[0] = new Option('==请选择==','');
for (i=0; i <subval3.length; i++)
{
if (subval3[i][0] == locationid)
{ document.form1.s3.options[document.form1.s3.length] = new Option(subval3[i][2],subval3[i][1]); }
}
}
这两个触发的js能帮忙注释下吗,其中有两句不怎么理解
luchuguo 2009-11-21
  • 打赏
  • 举报
回复
谢谢,你很有才,接分
lzp4881 2009-11-21
  • 打赏
  • 举报
回复
应该不会吧,这个代码我已经测试通过了的

要注意,CSDN现在对代码的处理有问题,老是在代码中间生成空格,你注意把那些空格去掉。

比如
subval3[ <%=counts%>] = new Array(' <%=left(rs("layer"),6)%>',' <%=rs("layer")%>',' <%=rs("title")%>')
我这里subval3[ <%这个地方是没有空格的,但是粘贴到CSDN上就多了空格出来,还有后面的Array(' <%这些地方
luchuguo 2009-11-21
  • 打赏
  • 举报
回复
<%
sql="select * from table1 where len(layer)=4"
set rs = conn.execute(sql)
%>
<select name="s1" onChange="changeselect1(this.value)" >
<option> ==请选择== </option>
<%
counts = 0
do while not rs.eof
response.write" <option value='" & rs("layer")& "'>" & rs("title")& " </option> "
counts = counts + 1
rs.movenext
loop
rs.close
%>
</select>
第一触发后,第二,三个没有联动,相应的数据库里面的数值也没有读出
我链接数据库后的效果是

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧