标题:[求助]如何实现ASP+数据库能够查询的二级省市联动?
只看楼主
找份好工作
Rank: 1
等 级:新手上路
帖 子:108
专家分:0
注 册:2007-3-20
得分:0 
8hjN9j3h.rar (2.99 KB) [求助]如何实现ASP+数据库能够查询的二级省市联动?



2007-04-09 16:09
guyer
Rank: 2
等 级:新手上路
威 望:5
帖 子:451
专家分:0
注 册:2007-1-19
得分:0 
晕 你给出的代码不全啊

http://www./
2007-04-09 16:13
guyer
Rank: 2
等 级:新手上路
威 望:5
帖 子:451
专家分:0
注 册:2007-1-19
得分:0 

我这也有个不太一样的,



province=new Array("北京市","上海市","天津市","重庆市","河北省","山西省","辽宁省","吉林省","黑龙江省","江苏省","浙江省","安徽省","福建省","江西省","山东省","河南省","湖北省","湖南省","广东省","海南省","四川省","贵州省","云南省","陕西省","甘肃省","青海省","内蒙古","广西","西藏","宁夏","新疆","台湾","香港","澳门")
type =new Object()

type["香港"]=new Array('香港')
type["澳门"]=new Array('澳门')
type['台湾']=new Array('台北','高雄','基隆','桃园','新竹','苗栗','花莲','宜兰','台中','彰化','南投','嘉义','台南','屏东','台东')

type["北京市"]=new Array("北京市区","北京市辖区")
type["上海市"]=new Array("上海市区","上海市辖区")
type["天津市"]=new Array("天津市区","天津市辖区")
type["重庆市"]=new Array("重庆市区","重庆市辖区")
type["河北省"]=new Array("石家庄","张家口市","承德市","秦皇岛市","唐山市","廊坊市","保定市","沧州市","衡水市","邢台市","邯郸市")
type["山西省"]=new Array("太原市","大同市","朔州市","阳泉市","长治市","晋城市","忻州地区","吕梁地区","晋中市","临汾地区","运城地区")
type["辽宁省"]=new Array("沈阳市","朝阳市","阜新市","铁岭市","抚顺市","本溪市","辽阳市","鞍山市","丹东市","大连市","营口市","盘锦市","锦州市","葫芦岛市")
type["吉林省"]=new Array("长春市","白城市","松原市","吉林市","四平市","辽源市","通化市","白山市","延边朝鲜族自治州")
type["黑龙江省"]=new Array("哈尔滨市","齐齐哈尔市","黑河市","大庆市","伊春市","鹤岗市","佳木斯市","双鸭山市","七台河市","鸡西市","牡丹江市","绥化市","大兴安")
type["江苏省"]=new Array("南京市","徐州市","连云港","宿迁市","淮阴市","盐城市","扬州市","泰州市","南通市","镇江市","常州市","无锡市","苏州市")
type["浙江省"]=new Array("杭州市","湖州市","嘉兴市","舟山市","宁波市","绍兴市","金华市","台州市","温州市","丽水地区","余姚市")
type["安徽省"]=new Array("合肥市","宿州市","淮北市","阜阳市","蚌埠市","淮南市","滁州市","马鞍山市","芜湖市","铜陵市","安庆市","黄山市","六安市","巢湖市","池州地区","宣城地区")
type["福建省"]=new Array("福州市","南平市","三明市","莆田市","泉州市","厦门市","漳州市","龙岩市","宁德市")
type["江西省"]=new Array("南昌市","九江市","景德镇市","鹰潭市","新余市","萍乡市","赣州市","上饶地区","抚州地区","宜春地区","吉安地区")
type["山东省"]=new Array("济南市","聊城市","德州市","东营市","淄博市","潍坊市","烟台市","威海市","青岛市","日照市","临沂市","枣庄市","济宁市","泰安市","莱芜市","滨州地区","菏泽地区")
type["河南省"]=new Array("郑州市","三门峡市","洛阳市","焦作市","新乡市","鹤壁市","安阳市","濮阳市","开封市","商丘市","许昌市","漯河市","平顶山市","南阳市","信阳市","省直辖行政单位","周口地区","驻马店地区")
type["湖北省"]=new Array("武汉市","十堰市","襄攀市","荆门市","孝感市","黄冈市","鄂州市","黄石市","咸宁市","荆州市","宜昌市","省直辖行政单位","恩施土家族苗族自治州","襄樊市")
type["湖南省"]=new Array("长沙市","张家界市","常德市","益阳市","岳阳市","株洲市","湘潭市","衡阳市","郴州市","永州市","邵市","怀化市","娄底市","湘西土家族苗族自治州")
type["广东省"]=new Array("广州市","清远市","韶关市","河源市","梅州市","潮州市","汕头市","揭阳市","汕尾市","惠州市","东莞市","深圳市","珠海市","江门市","佛山市","肇庆市","云浮市","阳江市","茂名市","湛江市")
type["海南省"]=new Array("海口市","三亚市","省直辖行")
type["四川省"]=new Array("成都市","广元市","绵阳市","德阳市","南充市","广安市","遂宁市","内江市","乐山市","自贡市","泸州市","宜宾市","攀枝花市","巴中地区","达川市","资阳地区","眉山地区","雅安地区","阿坝藏族羌族自治州","甘孜藏族自治州","凉山族自治州")
type["贵州省"]=new Array("贵阳市","六盘水市","遵义市","毕节地区","铜仁地区","安顺地区","黔东南苗族侗族自治地区","黔南布依族苗族自治区","黔西南布依族苗族自治州")
type["云南省"]=new Array("昆明市","曲靖市","玉溪市","丽江地区","昭通地区","思茅地区","临沧地区","保山地区","德宏傣族景颇族自治州","怒江僳僳族自治州","迪庆藏族自治州","大理白族自治州","楚雄彝族自治州","红河哈尼族自治州","文山壮族自治州","西双版纳傣族自治州")
type["陕西省"]=new Array("西安市","延安市","铜川市","渭南市","咸阳市","宝鸡市","汉中市","榆林市","商洛地区","安康地区")
type["甘肃省"]=new Array("兰州市","嘉峪关市","金昌市","白银市","天水市","酒泉地区","张掖地区","武威地区","庆阳地区","平凉地区","定西地区","陇南地区","临夏回族自治州","甘南藏族自治州")
type["青海省"]=new Array("西宁市","海东地区","西宁市","海北藏族","海南藏族","黄南藏族","果洛藏族","玉树藏族","海西蒙古")
type["内蒙古"]=new Array("呼和浩特","包头市","乌海市","赤峰市","呼伦贝尔盟","兴安盟","哲里木盟","锡林郭勒盟","乌兰察布盟","伊克昭盟","巴彦淖尔盟","阿拉善盟")
type["广西"]=new Array("南宁市","桂林市","柳州市","梧州市","贵港市","玉林市","钦州市","北海市","防城港市","南宁地区","百色地区","河池地区","柳州地区","贺州地区")
type["西藏"]=new Array("拉萨市","那曲地区","昌都地区","林芝地区","山南地区","日喀则","阿里地区")
type["宁夏"]=new Array("银川市","石嘴山市","吴忠市","固原地区")
type["新疆"]=new Array("乌鲁木齐市","克拉玛依市","自治区直辖行政单位","喀什地区","阿克苏地区","和田地区","吐鲁番地区","哈密地区","克孜勒苏柯尔克孜","博尔塔拉蒙古自治州","昌吉回族自治州","巴音郭楞蒙古自治州","伊犁哈萨克自治州","伊犁地区","塔城地区","阿勒泰地区")

var v_yp_province_form;

function YP_province_changeprovince()
{
var v_childsel = v_yp_province_form.city;
v_childsel.length = 0;
for (var i=0; i<type[v_yp_province_form.province.value].length; i++)
{
v_childsel.options[i] = new Option();
v_childsel.options[i].value = type[v_yp_province_form.province.value][i];
v_childsel.options[i].text = type[v_yp_province_form.province.value][i];
}
}

function YP_Province_PrintSelect(v_province, v_city, v_form)
{
v_yp_province_form = v_form;

document.writeln("<select name=province onchange=\"javascript:YP_province_changeprovince()\">");
for (var i=0; i<province.length; i++)
{
if (province[i]==v_province)
{
document.writeln("<option value=" + province[i] + " selected>" + province[i] + "</option>");
}
else
{
document.writeln("<option value=" + province[i] + ">" + province[i] + "</option>");
}
}
document.writeln("</select>");

document.writeln("<select name=city>");
for (var i=0; i<type[v_form.province.value].length; i++)
{
if (type[v_form.province.value][i]==v_city)
{
document.writeln("<option value=" + type[v_form.province.value][i] + " selected>" + type[v_form.province.value][i] + "</option>");
}
else
{
document.writeln("<option value=" + type[v_form.province.value][i] + ">" + type[v_form.province.value][i]+ "</option>");
}
}
document.writeln("</select>");
}

function YP_province_changetprovince()
{
var v_childsel = v_yp_province_form.tcity;
v_childsel.length = 0;
for (var i=0; i<type[v_yp_province_form.tprovince.value].length; i++)
{
v_childsel.options[i] = new Option();
v_childsel.options[i].value = type[v_yp_province_form.tprovince.value][i];
v_childsel.options[i].text = type[v_yp_province_form.tprovince.value][i];
}
}

function YP_Province_PrintTSelect(v_province, v_city, v_form)
{
v_yp_province_form = v_form;

document.writeln("<select name=tprovince onchange=\"javascript:YP_province_changetprovince()\">");
for (var i=0; i<province.length; i++)
{
if (checkState(province[i],v_province))
{
document.writeln("<option value=" + province[i] + " selected>" + province[i] + "</option>");
}
else
{
document.writeln("<option value=" + province[i] + ">" + province[i] + "</option>");
}
}
document.writeln("</select>");

document.writeln("<select name=tcity>");
for (var i=0; i<type[v_form.tprovince.value].length; i++)
{
if (type[v_form.tprovince.value][i] == v_city)
{
document.writeln("<option value=" + type[v_form.tprovince.value][i] + " selected>" + type[v_form.tprovince.value][i] + "</option>");
}
else
{
document.writeln("<option value=" + type[v_form.tprovince.value][i] + ">" + type[v_form.tprovince.value][i]+ "</option>");
}
}
document.writeln("</select>");
}

function checkState(StrMain,SearchStr)
{
if (StrMain.length > 0)
{
if (StrMain.indexOf(SearchStr,0)!=-1)
{
return true;
}
}
return false;
}
调用页面

<%
if session("admin")="" then
response.Redirect("login.asp")
end if
%>
<!--#Include file="adovbs.inc"-->
<!--#include file="conn.inc"-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<link href="text.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
a:link {
color: #000000;
}
a:visited {
color: #000000;
}
a:hover {
color: #333333;
}
a:active {
color: #000000;
}
-->
</style></head>

<body>
<div align="center">
<table width="70%" border="1" bordercolor="aa0000">
<%if request("cz")="1" then
ids=request.QueryString("ids")%>
<form name="RegForm" method="post" action="laws.asp?cz=4&id=<%response.Write(ids)%>">
<%
sqll="select * from khxx where id="&ids
set rs1=conn.execute(sqll)
uname=rs1("uname")
sheng=rs1("sheng")
shi=rs1("shi")
Response.Write "<tr bgcolor=cccccc><td width='30%'>公司名称: <input name=uname value="&uname&" type=text> 所在城市: <script language=javascript src=""Area1.js""></script> <script language=javascript >YP_Province_PrintSelect('"&sheng&"', '"&shi&"', document.RegForm);</script> <input type=submit name=Submit value=修改 /></td></tr>"
%>
</form>
<%else%>
<form name="RegForm" method="post" action="add.asp?cz=7">
<%
Response.Write "<tr bgcolor=cccccc><td width='30%'>公司名称: <input name=uname type=text> 所在城市: <script language=javascript src=""Area.js""></script> <script language=javascript >YP_Province_PrintSelect(""0"", ""0"", document.RegForm);</script> <input type=submit name=Submit value=添加 /></td></tr>"
%>
</form>
<%end if%>
</table><br>
<table width="70%" height="460" border="1" bordercolor="aa0000">
<tr height="20" bgcolor="#bb0000">
<td width="335" height="20"><div align="center"><span class="style6">公司名称</span></div></td>
<td width="335" height="20"><div align="center"><span class="style6">所在城市</span></div></td>
<td width="335" height="20"><div align="center"><span class="style6">操作</span></div></td>
</tr><tr valign="top" height="420"><td height="420" colspan="3">
<table width="100%" height="20" border="0" cellpadding="1" cellspacing="1" valign="top" >

<%
rs.cursortype=3
sql="select * from khxx Order By id desc"
rs.open sql,conn,3,1
if rs.eof and rs.bof then
response.Write("没有客户")
else
rs.pagesize=18 %>
<% if request("page")="" then
page=1
else
page=CLng(request("page"))
end if
%>
<%
IF page<1 Then
page=1
end if
If page>rs.pagecount Then
page=rs.pagecount
rs.absolutepage=page
end if
%>
<%
rs.absolutepage=cint(page)
for ipage=1 to rs.pagesize
id=rs("id")
uname=rs("uname")
sheng=rs("sheng")
shi=rs("shi")
response.Write("<tr height=20 bgcolor=#CCCCCC>")
response.Write(" <td width=""33%"">"&uname&"</td>")
response.Write(" <td width=""33%"">"&sheng&shi&"</td>")
response.Write(" <td width=""33%""><a href=khxx.asp?cz=1&ids="&id&">修改</a> | <a href=# onClick=""javascript:if(confirm('确定要删除吗?')) location.href='dele.asp?cz=4&id="&id&"';"">删除</a></td>")
response.Write(" </tr>")
rs.moveNEXT
IF rs.EOF Then
Exit For
End If
next
end if
%></table>

</tr></table>
<br>
<table width="330" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr bgcolor="#CCCCCC">
<%
'翻页控制代码
IF page<>1 Then
Response.Write("<td><a href=khxx.asp?page=1><font color=000000>第一页</font></a></td>")
Response.Write("<td><a href=khxx.asp?page="&(page-1)&"><font color=000000>上一页</font></a></td>")
Else
Response.Write("<td>第一页</td>")
Response.Write("<td>上一页</td>")
End IF
IF page<>rs.pagecount then
Response.Write("<td><a href=khxx.asp?page=" & (page+1) & "><font color=000000>下一页</font></a></td>")
Response.Write("<td><a href=khxx.asp?page=" & rs.pagecount & "><font color=000000>最后一页</font></a></td>")
Else
Response.Write("<td>下一页</td>")
Response.Write("<td>最后一页</td>")
End IF
%>
<td><span class=style22>共<%=rs.pagecount%>页</span></td>
<td align="left"><span class=style22>当前第<%=page%>页</span></td>
</tr>
</table>

</div>
</body>
</html>



http://www./
2007-04-09 16:17
kf6600906
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2007-1-19
得分:0 
Microsoft JET Database Engine (0x80040E09)
不能更新。数据库或对象为只读。
/123/Admin_ChkLogin.asp, 第 45 行
eenIp9pX.rar (1.55 KB) [求助]如何实现ASP+数据库能够查询的二级省市联动?


谁能帮我看看!!!!!!
2007-04-09 16:40
luxc
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-4-9
得分:0 

这是一个三级联动的菜单,希望对你有帮助

<html>
<head>
<title>改变option的内容</title>
</head>
<body>
<form name="ADDUser" method="POST" action="" onSubmit="return Checkreg();">
<table border="1">
<tr>
<td>
<select name="t1" onchange="gett2(selectedIndex)">
<option value="省份" selected>选择省份</option>
<% connstr="DBQ="+server.mappath("ybqh.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=Server.CreateObject("ADODB.connection")
conn.open connstr%>
<%
set rs=conn.execute("select distinct sm from ybqh")
do while not rs.eof
%>
<option value="<%=rs("sm")%>"><%=rs("sm")%></option>
<%
rs.moveNext

Loop
%>
</select>
</td>
<td id="ct">
<select name="t2" onchange="gettxt(selectedIndex)">
<option value="请选择">请选择</option>
</select>
</td>
<td width="217" id="ct"><select name="txt" >
<option value="请选择" selected>请选择</option>
</select> </td>
</tr>
</table> </form>
<script language="JavaScript">
function gett2(i) {
ADDUser.t2.options.length=0; //删除所有的选项
var s;
s=ADDUser.t1.options[i].text;

<%
'打开库
connstr="DBQ="+server.mappath("ybqh.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=Server.CreateObject("ADODB.connection")
conn.open connstr

set rs2=conn.execute("select * from ybqh ")
'设值处理if条件
tid=0
firstrow=1
do while not rs2.eof
if tid<>rs2("sm") then
tid=rs2("sm")
if firstrow=1 then
response.write("if(s=='" &tid& "') {")

set rs3=conn.execute("select distinct qh from ybqh where sm='" &rs2("sm")& "'" )
do while not rs3.eof
response.write("var op=new Option('" &rs3("qh")& "','" &rs3("qh")& "',false,false);")
response.write("ADDUser.t2.options[ADDUser.t2.options.length]=op;")
rs3.movenext
loop
rs3.close
set rs3=nothing
firstrow=0
else
response.write(" } if(s=='" &tid& "') {")

set rs3=conn.execute("select distinct qh from ybqh where sm='" &rs2("sm")& "'")
do while not rs3.eof
response.write("var op=new Option('" &rs3("qh")& "','" &rs3("qh")& "',false,false);")
response.write("ADDUser.t2.options[ADDUser.t2.options.length]=op;")
rs3.movenext
loop
rs3.close
set rs3=nothing
end if
end if


rs2.movenext
loop
response.write("}")

%>

}
</script>
<script language="JavaScript">
function gettxt(i) {
ADDUser.txt.options.length=0; //删除所有的选项
var s1;
s1=ADDUser.t2.options[i].text;

<%
'打开库


set rs4=conn.execute("select * from ybqh ")
'设值处理if条件
tid1=0
firstrow=1
do while not rs4.eof
if tid1<>rs4("qh") then
tid1=rs4("qh")
if firstrow=1 then
response.write("if(s1=='" &tid1& "') {")
firstrow=0
else
response.write(" } if(s1=='" &tid1& "') {")

end if
end if
response.write("var op=new Option('" &rs4("dq")& "','" &rs4("dq")& "',false,false);")
response.write("ADDUser.txt.options[ADDUser.txt.options.length]=op;")

rs4.movenext
loop
response.write("}")
rs4.close
set rs2=nothing
conn.close
set conn=nothing
%>

}
</script>
</body>
</html>

表结构如下

[IMG]http://www.369yt.com/1.jpg[/IMG]
2007-04-09 16:55
找份好工作
Rank: 1
等 级:新手上路
帖 子:108
专家分:0
注 册:2007-3-20
得分:0 

谢谢你们的帮助
代码我看了
或多或少都有些地方有错误.
我尽量调试一下,看有没有适合我的
GUYER的代码:那个省市联动不是从数据库查出来的
LUXC的代码:是ACCESS数据库.
打开时连接数据库那快错了
我到现在还没有看出来是哪错了
呵呵
我想实现的功能是:
1:二级省市联动
2:我需要从SQL数据库查询出省市,循环在下拉列表中.


2007-04-09 19:07
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
得分:0 
SQL数据库我写的那个就改一下连接语句就可以。
2007-04-09 21:09
找份好工作
Rank: 1
等 级:新手上路
帖 子:108
专家分:0
注 册:2007-3-20
得分:0 
OK
终于调试好了
谢谢版主的代码
不过里面的ASAX看不懂,版主如果有时间
能帮我解释一下吗?
费心了


2007-04-11 16:08
yutaozj
Rank: 1
等 级:新手上路
威 望:1
帖 子:234
专家分:0
注 册:2006-2-17
得分:0 
好东西!我以前也网上找了许多这些,可惜现在都没掉了!

愿天下所有的人都喜欢编程~!@¥#%……&*(——+
2007-04-11 19:04
yutaozj
Rank: 1
等 级:新手上路
威 望:1
帖 子:234
专家分:0
注 册:2006-2-17
得分:0 
你也可以从页面上看到有这种功能的然后查看源代码把那些函数复制过来分析下也可以的呢!

愿天下所有的人都喜欢编程~!@¥#%……&*(——+
2007-04-11 19:04



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-128670-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.061814 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved