<%
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 = "select * from S_District order by districtid asc"
rs2.open sql2,conn,1,1
%>
<script language = "JavaScript">
var onecount2;
onecount2=0;
subcat2 = new Array();
<%
count2 = 0
do while not rs2.eof
%>
subcat2[<%=count2%>] = new Array("<%= trim(rs2("Districtname"))%>","<%= trim(rs2("Cityid"))%>","<%= trim(rs2("Districtid"))%>");
<%
count2 = count2 + 1
rs2.movenext
loop
rs2.close
set rs2=nothing
%>
onecount2=<%=count2%>;
function chsel2(districtid)
{
document.myform.class3.length = 0;
var districtid=districtid;
var j;
document.myform.class3.options[0] = new Option('==请选择县==','');
for (j=0;j < onecount2; j++)
{
if (subcat2[j][1] == districtid)
{
document.myform.class3.options[document.myform.class3.length] = new Option(subcat2[j][0], subcat2[j][2]);
详细解决方案
从网上下了一个省市县三级联动的代码。解决方法
热度:383 发布时间:2013-12-28 22:19:33.0
相关解决方案
- IE不支持JQuery吗?解决方法
- boa+cgi+sqlite3【基于web的数据采集并动态显示】解决方法
- cgi提取文件内容?解决方法
- java.lang.NoSuchMethodException: setId([Ljava.lang.String;)解决方法
- s标签 图片src 当action 解析?解决方法
- CAPTCHA 模块中 ajax form 导致CAPTCHA session reuse attack detected异常,解决方法
- java编程思想.解决方法
- SSH框架导入struts,hibernate,spring分先后顺序吗>>解决方法
- 关于遮罩层的。解决方法
- oracle 最近的时间(而不是前一天的时间) 跪求sql语句 。解决方法
- web service No services have been found.解决方法
- socket.connect(socketAddress,timeout ))解决方法
- description The requested resource (/gongqiu/goindex.action) is not available.解决方法
- javascript中===什么意思?解决方法
- struts工作流程~解决方法
- 求struts2玩的顺的人!解决方法
- Mybatis的mapper.是个接口?解决方法
- 求教一个关于两个list的类似求并集的算法。解决方法
- jquery+ajax网页被卡死,cpu爆掉! - -解决方法
- 怎样实现分页.解决方法
- mapping.findForward()执行后,没有跳转页面?解决方法
- Tomcat7 不支持这句代码,为什么?解决方法
- 经典<<thinking in java >>电子书+课后习题解答.解决方法
- 现在做的一个项目,遇到个坑爹的需求。解决方法
- 在servlet中存了cookie后,再转发到jsp,在jsp上得不到存的cookie, 可是一刷新就得到了,这是为什么?解决方法
- Cannot load JDBC driver class 'com.microsoft.jdbc.sqlserver.SQLServerDriver'解决方法
- 关于Struts2的list集合里面重复的值的处理办法。解决方法
- 关于servlet,晕了。解决方法
- 统计查询中的查询判断.解决方法
- jdk1.7改成jdk1.6要改哪里?解决方法