日期:2014-05-16 浏览次数:20845 次
<%
Option Explicit
'数据库:
'test
'表1 S_Province 省 表
' 字段
' ProvinceID (主键)
' ProvinceName 名字
'表2 S_City 市 表
' 字段
' CityID (主键)
' CityName 名字
' ProvinceID
'表3 S_District 区县 表
' 字段
' DistrictID (主键)
' DistrictName
' CityID
%>
<!--#include file="conn.asp"-->
<html>
<head>
<title>asp三级联动菜单(含数据库)</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<%
dim conn
dim rs
dim sql
dim count
dim rs1
dim sql1
dim rs2
dim sql2
dim count2
dim connstr
set rs=server.createobject("adodb.recordset")
sql = "select * from S_City order by CityID"
rs.open sql,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("CityName"))%>","<%= trim(rs("Provinceid"))%>","<%= trim(rs("CityID"))%>");
<%
count = count + 1
rs.movenext
loop
rs.close
set rs=nothing
%>
onecount=<%=count%>;
function chsel1(provinceid)
{
document.myform.class2.length = 0;
document.myform.class3.length = 0;
document.myform.class3.options[0] = new Option('==请选择省==','');
var provinceid=provinceid;
var i;
document.myform.class2.options[0] = new Option('==请选择市==','');
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == provinceid)
{
document.myform.class2.options[document.myform.class2.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
</script>
<%
set rs2=server.createobject("adodb.recordset")
sql2