下拉列表两级连动的新方法(一)
来源:asp之家 时间:2009-06-04 18:18:00
这是网站制作很流行的下拉列表两级连动的代码,也是很多人使用的代码。
下面,先来看这段代码:
<%dim count
set rs=server.createobject("adodb.recordset")
rs.open "select * from shop_Nclass order by Nclassidorder ",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.myform.Nclassid.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.myform.Nclassid.options[document.myform.Nclassid.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
</script>
在<body>..</body>之间:
<%
rs.open "select * from shop_anclass order by anclassidorder",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.myform.anclassid.options[document.myform.anclassid.selectedIndex].value)" class="wenbenkuang">
<option selected value="<%=rs("anclassid")%>"><%=trim(rs("anclass"))%></option>
<% dim selclass
selclass=rs("anclassid")
rs.movenext
do while not rs.eof
%>
<option value="<%=rs("anclassid")%>"><%=trim(rs("anclass"))%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select>
小类
<select name="Nclassid" class="wenbenkuang">
<%rs.open "select * from shop_Nclass where anclassid="&selclass ,conn,1,1
if not(rs.eof and rs.bof) then
%>
<option selected value="<%=rs("NclassID")%>"><%=rs("Nclass")%></option>
<% rs.movenext
do while not rs.eof%>
<option value="<%=rs("NclassID")%>"><%=rs("Nclass")%></option>
<% rs.movenext
loop
end if
rs.close
set rs = nothing
%>
</select>
从整体上看,这个代码没有什么问题,我也曾经使用过这个代码,认为很时用。但是随着时间的迁移,它的问题也一点点的暴露出来,我们一起来想一下:当供选择的项越来越多时或访问此页面的人越来越多时,数据库的压力也越来越大,最后终于让服务器不堪重负,网页打开越来越慢,最后重新,然后再访问,再变慢,再重启。难道就没有什么有效的方法吗?
答案:当然是有的。
我们都知道,VBScript是在服务器端运行的,而JScript是在客户端运行的,如果把VBScript的代码使用JScript的代码代替,那么就减少了服务器端的压力,关键是如何转化成JScript代码呢?


猜你喜欢
mysql正确安全清空在线慢查询日志slow log的流程分享
浅析Python中变量用法
python 实现数组list 添加、修改、删除的方法
记一次python 爬虫爬取深圳租房信息的过程及遇到的问题

js下用eval生成JSON对象
简单了解python中对象的取反运算符

Python自定义聚合函数merge与transform区别详解
Oracle 8i字符集乱码问题析及其解决办法
CentOS 6.6服务器编译安装lnmp(Nginx1.6.2+MySQL5.6.21+PHP5.6.3)

ES6中的Promise代码详解
Python如何实现文本转语音
Dreamweaver初学者常见问题解答
pytorch索引查找 index_select的例子
mysql的group_concat函数使用示例
深入理解ES6中let和闭包
vue中项目页面空白但不报错产生的原因及分析

Python编程使用PyQt5制作动态钟表示例
