欢迎光临
我们一直在努力

省市联动菜单的源代码实现(access数据库版)-ASP教程,数据库相关

建站超值云服务器,限时71元/月

在网上经常看到关于联动菜单的贴子,特将自己的代码贴出来,供大学参与.

一.数据库:

表1:region(id,province)

表2:city(id,city,province)

二.代码实现:

<!–#include file="conn.asp"–>

<%

function dbcombox()

dim rs,sql,msg

sql = "select * from region"

set rs = conn.execute(sql)

while not rs.eof

msg = msg & "<option value=""" & rs("province") & """>" & rs("province") & "</option>"

rs.movenext

wend

rs.close

set rs = nothing

dbcombox = msg

end function

%>

<html>

<head>

<meta http-equiv="content-language" content="zh-cn">

<meta http-equiv="content-type" content="text/html; charset=gb2312">

<title>会员登录</title>

</head>

<body>

<script language ="javascript" >

citys = new array();

<%

dim rs,sql,i

sql = "select * from city"

set rs = conn.execute(sql)

i = 0

while not rs.eof

%>

citys[<%=i%>] =new array("<%=rs("province")%>","<%=rs("city")%>");

<%

i = i + 1

rs.movenext

wend

rs.close

set rs = nothing

%>

function changeselect(selvalue){

var selvalue = selvalue;

var i;

document.form1.city.length = 0 ;

document.form1.city.options[document.form1.city.length] = new option("请选择","");

for (i = 0 ;i <citys.length;i++){

if(citys[i][0]==selvalue){

document.form1.city.options[document.form1.city .length] = new option(citys[i][1],citys[i][1]);

}

}

}

document.form1.city.options[document.form1.city.length] = new option("请选择","");

</script>

<div align="center">

<form method="post" action="forum.asp" name="form1">

<table border="0" cellpadding="0" style="border-collapse: collapse" width="100%" id="table1" height="59">

<tr>

<td width="67" height="30" bgcolor="#d4d0c8"><b><font size="2">地区</font></b></td>

<td height="30" bgcolor="#d4d0c8"><select size="1" name="region" onchange ="changeselect(document.form1.region.options[document.form1.region.selectedindex].value)">

<%=dbcombox()%></select></td>

</tr>

<tr>

<td width="67" height="30"><b><font size="2">城市</font></b></td>

<td height="30"><select size="1" name="city"></select></td>

</tr>

</table>

</form>

</div>

</body>

</html>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 省市联动菜单的源代码实现(access数据库版)-ASP教程,数据库相关
分享到: 更多 (0)

相关推荐

  • 暂无文章