编写一个含二级目录的源码(Asp+JavaScript)
程序员文章站
2023-11-17 21:01:34
********************** (一) 打开记录集,创建数组,把记录集的值赋给数组. <% dim count...
********************** (一) 打开记录集,创建数组,把记录集的值赋给数组.
<%
dim count
set rs=server.createobject("adodb.recordset")
sql = "select * from bookboard order by classid desc"
rs.open sql,cn,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("boardname"))%>","<%= trim(rs("classid"))%>","<%= trim(rs("boardid"))%>");
<%count = count + 1
rs.movenext
loop
rs.close%>
onecount=<%=count%>;
function changelocation(locationid)
{document.form1.boardid.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{if (subcat[i][1] == locationid)
{document.form1.boardid.options[document.form1.boardid.length] = new option(subcat[i][0], subcat[i][2]);
}}}
</script>
********************** (二) 显示分组,并编写列表框的onchange事件.
<%set rs=server.createobject("adodb.recordset")
sql="select * from bookclass order by classid desc"
rs.open sql,cn,1,1
if rs.eof and rs.bof then
response.write "请先添加总类。"
response.end
else%>
<select name="classid" onchange="changelocation(document.form1.classid.options[document.form1.classid.selectedindex].value)">
<option selected value="">==请选择大类==</option>
<% do until rs.eof%>
<option value="<%=trim(rs("classid"))%>"><%=trim(rs("classname"))%></option>
<%rs.movenext
loop
end if
rs.close
set rs = nothing%>
</select>
<select name="boardid"><option selected value="">==请选择小类==</option>
</select>
<%
dim count
set rs=server.createobject("adodb.recordset")
sql = "select * from bookboard order by classid desc"
rs.open sql,cn,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("boardname"))%>","<%= trim(rs("classid"))%>","<%= trim(rs("boardid"))%>");
<%count = count + 1
rs.movenext
loop
rs.close%>
onecount=<%=count%>;
function changelocation(locationid)
{document.form1.boardid.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{if (subcat[i][1] == locationid)
{document.form1.boardid.options[document.form1.boardid.length] = new option(subcat[i][0], subcat[i][2]);
}}}
</script>
********************** (二) 显示分组,并编写列表框的onchange事件.
<%set rs=server.createobject("adodb.recordset")
sql="select * from bookclass order by classid desc"
rs.open sql,cn,1,1
if rs.eof and rs.bof then
response.write "请先添加总类。"
response.end
else%>
<select name="classid" onchange="changelocation(document.form1.classid.options[document.form1.classid.selectedindex].value)">
<option selected value="">==请选择大类==</option>
<% do until rs.eof%>
<option value="<%=trim(rs("classid"))%>"><%=trim(rs("classname"))%></option>
<%rs.movenext
loop
end if
rs.close
set rs = nothing%>
</select>
<select name="boardid"><option selected value="">==请选择小类==</option>
</select>