ASP

本类阅读TOP10

·asp常用数据库连接方法和技巧
·无组件生成BMP验证码
·一些常用的辅助代码 (网络收藏)
·JavaScript实现的数据表格:冻结列、调整列宽和客户端排序
·VisualStudio.NET_2003及其 MSDN 下载地址
·ASP模拟MVC模式编程
·图片以二进制流输出到网页
·MD5加密算法 ASP版
·ASP.NET编程中的十大技巧
·改进 ASP 的字符串处理性能

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
省市联动菜单的源代码实现(access数据库版)

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

在网上经常看到关于联动菜单的贴子,特将自己的代码贴出来,供大学参与.
一.数据库:
表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>




相关文章

相关软件