级联问题

hailun 2006-12-28 03:11:07
下面是一个产品搜索的二级级联
不过只有一处是不同的,但功能却完全一样
就是在第二个段码处的"小类selct处循环了一下"而上面这个没有循环,为什么功能还是一样的呢?区别在哪里呢?


------------------小类select没有循环-----------------------------------
<!--#include file="conn.asp"-->
<%
set rs=server.createobject("adodb.recordset")
sql="select * from smallclass"
rs.open sql,conn,1,1
%>
<script language="javascript">
var onecount;
subcat=new Array();
<%
count=0
do while not rs.eof
%>
subcat[<%=count%>]=new Array("<%=rs("smallclassname")%>","<%=rs("bigclassname")%>","<%=rs("smallclassname")%>");
<%
count=count+1
rs.movenext
loop
rs.close
%>
onecount=<%=count%>;
function changelocation(locationid){
document.myform.SmallClassName.length = 1;
var locationid=locationid;
var i;
for(i=0;i<onecount;i++){
if(locationid==subcat[i][1]){
document.myform.SmallClassName.options[document.myform.SmallClassName.length] = new Option(subcat[i][0], subcat[i][2]);
}
}

}
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<form action="search.asp" name="myform">
<tr>
<td><select name="Field" size="1">
<option value="title" selected>产品名称</option>
<option value="content">产品说明</option>
</select>
</td>
</tr>
<tr>
<td><select name="bigclassname" onChange="changelocation(document.myform.bigclassname.options[document.myform.bigclassname.selectedIndex].value)" size="1">
<option value="" selected>请选择大类</option>
<%
sql="select * from bigclass"
rs.open sql,conn,1,1
do while not rs.eof
%>
<option value="<%=rs("bigclassname")%>"><%=rs("bigclassname")%></option>
<%
rs.movenext
loop
%>
</select>
</td>
</tr>
<tr>
<td>
<select name="SmallClassName">
<option value="" selected>所有小类</option>
</select>
</td>
</tr>
<tr>
<td> </td>
</tr>
</form>
</table>
-------------------------------------------------------------------------


------------------------有循环--------------------------------------
<!--#include file="conn.asp"-->
<%
set rs=server.createobject("adodb.recordset")
sql="select * from SmallClass order by SmallClassID asc"
rs.open sql,conn,1,1
%>
<script language = "JavaScript">
var onecount;
subcat = new Array();
<%
count = 0
do while not rs.eof
%>
subcat[<%=count%>] = new Array("<%= trim(rs("SmallClassName"))%>","<%= trim(rs("BigClassName"))%>","<%= trim(rs("SmallClassName"))%>");
<%
count = count + 1
rs.movenext
loop
rs.close
%>
onecount=<%=count%>;

function changelocation(locationid)
{
document.myform.SmallClassName.length = 1;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.myform.SmallClassName.options[document.myform.SmallClassName.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}

</script>
<body topmargin=0>
<form id="form1" name="myform" method="post" action="productadd">
<table width=760 border="1" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2" align="center">添加产品</td>
</tr>
<tr>
<td width="13%">产品类别:</td>
<td width="87%" colspan="2">
<%
sql="select * from BigClass"
rs.open sql,conn,1,1
if rs.eof or rs.bof then
response.Write("请先添加栏目")
else
%>
<select name="BigClassName" onChange="changelocation(document.myform.BigClassName.options[document.myform.BigClassName.selectedIndex].value)" size="1">
<option selected value="<%=rs("BigClassName")%>"><%=rs("BigClassName")%></option>
<%
dim selclass
selclass=rs("BigClassName")
rs.movenext
do while not rs.eof
%>
<option value="<%=rs("BigClassName")%>"><%=rs("BigClassName")%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select>
<select name=SmallClassName>
<option value="" selected>不指定小类</option>
<%
sql="select * from SmallClass where BigClassName='"&selclass&"'"
rs.open sql,conn,1,1
if not(rs.eof and rs.bof) then
%>
<option value="<%=rs("SmallClassName")%>"><%=rs("SmallClassName")%></option>
<%
rs.movenext
do while not rs.eof
%>
<option value="<%=rs("SmallClassName")%>"><%=rs("SmallClassName")%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select>
</td>
</tr>
<tr>
<td>产品名称:</td>
<td><input type="text" name="pid" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="提交"><input type="reset" value="重置"></td>
</tr>
</table>
</form>

...全文
159 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
dh20156 2007-01-17
  • 打赏
  • 举报
回复
脚本没什么区别,因为JS部分都是一样的,只要大类改变,小类SELECT自动填充相应的OPTION;
而第二段小类有一个循环,只是先将小类列出来了:

<select name=SmallClassName>
<option value="" selected>不指定小类</option>
<%
sql="select * from SmallClass where BigClassName='"&selclass&"'"
rs.open sql,conn,1,1
if not(rs.eof and rs.bof) then
%>
<option value="<%=rs("SmallClassName")%>"><%=rs("SmallClassName")%></option>
<%
rs.movenext
do while not rs.eof
%>
<option value="<%=rs("SmallClassName")%>"><%=rs("SmallClassName")%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select>
hailun 2006-12-30
  • 打赏
  • 举报
回复
朋友们?
就一小段代码比较一下吧
hailun 2006-12-29
  • 打赏
  • 举报
回复
呵呵,代码是长了点,但问题我想应该是很简单,但我理解不了,所以发个贴求问
hailun 2006-12-29
  • 打赏
  • 举报
回复
沉了
lcw321321 2006-12-28
  • 打赏
  • 举报
回复
代码这么长,只给10分,也太少了吧

28,390

社区成员

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

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