| 网站首页 | 业界新闻 | 群组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 编程论坛
大量收QQ微信精准粉/交友粉,非诚勿扰千里之行 始于足下
共有 649 人关注过本帖
标题:asp 联动菜单问题
只看楼主 加入收藏
wyslsm
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2015-3-29
结帖率:66.67%
  问题点数:0  回复次数:1   
asp 联动菜单问题
网上复制的代码,数据库根据网上介绍制作,为什么第二个选择菜单没有数据?(第一个选择菜单有数据)

请教

全部代码如下:


<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
  dim conn
  set conn =server.createobject("adodb.connection")
  conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&server.MapPath("db\database1.mdb")
%>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<table width="1002" border="0">
  <tr>
    <td height="253"><form id="form1" name="form1" method="post" action="">
      <p>
        <label for="select"></label>
        <select name="Province_select" onChange=chsel()>
        <option value="xxx" selected>请选择省份……</option>
        <%
          dim tmpid  '定义一个临时变量用来记住省id
          tmpid=0
         
          set rs_Province=server.CreateObject("ADODB.recordset")
          sql="select * from Province order by ProvinceOrder"
          rs_Province.open sql,conn,1,1
          while not rs_Province.eof
          tmpid=rs_Province("id")
          %>
            <option value="<%=rs_Province("ProvinceNo")%>" ><%=trim(rs_Province("ProvinceName"))%></option>
         <%
          rs_Province.movenext
          wend
          rs_Province.close
          set rs_Province=nothing
         %>
        </select>
      </p>
      <p>&nbsp;</p>
      <p>
        <label for="select2"></label>
        <select name="City_select">
        <%
         set rs_City=server.createobject("adodb.recordset")
         sql="select * from City where ProvinceID="&tmpid&" order by CityOrder"
         rs_City.open sql,conn,1,1
         while not rs_City.eof
         %>
          <option value="<%=rs_City("CityNo")%>"><%=trim(rs_City("CityName"))%></option>
         <%
         rs_City.movenext
         wend
         rs_City.close
         set rs_City=nothing
        %>
        </select>
      </p>
    </form></td>
  </tr>
</table>

<script language=JavaScript>
<%
         dim sql,i,j
         '//////////////////////////读出 Province 表//////////////////////////

         set rs_Province=server.createobject("adodb.recordset")
         sql="select * from Province order by ProvinceOrder"
         rs_Province.open sql,conn,1,1
         %>
         var selects=[];
         selects['xxx']=new Array(new Option('请选择城市……','xxx'));
         <%
         for i=1 to rs_s.recordcount
         %>
         
        selects['<%=rs_Province("ProvinceNo")%>']=new Array(
        <%
        '//////////////////////////读出 City 表//////////////////////////

        set rs_City=server.createobject("adodb.recordset")
        sql="select * from City where ProvinceID="&rs_Province("id")&" order by ProvinceOrder"
        rs_City.open sql,conn,1,1
        if rs_City.recordcount>0 then
           for j=1 to rs_City.recordcount
              if j=rs_City.recordcount then
        %>
      
        new Option('<%=trim(rs_City("CityName"))%>','<%=trim(rs_City("CityNo"))%>'));
        <%else%>
  
        new Option('<%=trim(rs_City("Cityname"))%>','<%=trim(rs_City("CityNo"))%>'),
        <%
        end if
        rs_City.movenext
        next
        else
        %>
        new Option('','0'));
      
        <%
        end if
        rs_City.close
        set rs_City=nothing
        rs_Province.movenext
        next
        rs_Province.close
        set rs_Province=nothing
       %>
 
      <!--//////////JavaScript控制联动///////////-->
      function chsel(){
         with (document.form1){
           if(province_select.value) {
                city_select.options.length=0;
                for(var i=0;i<selects[province_select.value].length;i++){
                     city_select.add(selects[province_select.value][i]);
    }
   }
  }
 }
</script>

</body>
</html>
2017-10-22 12:22
klyz505
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:37
专家分:121
注 册:2009-1-22
  得分:0 
1、按程序逻辑,tmpid记录的是最后一个省份的id,默认情况下,城市出现的是最后一个省份下的城市。请检查数据中,最后一个省份下是否有城市数据。
2、你的js代码要注意大小写,代码因为大小写问题而存在问题,选择省份时执行不了。
2017-10-30 14:00







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

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