标题:如何实现 asp+access 无刷新联动菜单
只看楼主
wyslsm
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2015-3-29
结帖率:66.67%
 问题点数:0 回复次数:2 
如何实现 asp+access 无刷新联动菜单
如何让第二级菜单与第一级菜单联动

代码:
<!--选择项目-->
<%
rst1.open "xm",conn,1,1
zts1=rst1.recordcount
for k1=1 to zts1
%>
<option value="<%=rst1("xm_mc")%>"><%=rst1("xm_mc")%></option>
<%
rst1.movenext
if rst1.eof=true then
exit for
end if
next
%>
</select>
</p>
</form>
<p> </p>
<form id="form3" name="form3" method="post" action="">
<label for="select5"></label>
<select name="cd_pb" id="select5" onchange="changeSelect(this.selectedIndex)">

<!--选择评比内容-->
<%
Sql2="select * from pb where xm_id=2 "'&dm_xmid
rst2.open Sql2,conn,1,1
zts2=rst2.recordcount
for k2=1 to zts2
%>
<option value="<%=rst2("pbnr")%>"><%=rst2("pbnr")%></option>
<%
rst2.movenext
if rst2.eof=true then
exit for
end if
next
%>
</select>
</form>
<p> </p>
<form id="form4" name="form4" method="post" action="">
<p>
<label for="select6"></label>
<select name="cd_jc" id="select6">
搜索更多相关主题的帖子: 菜单 -- for select form 
2017-10-21 17:02
wyslsm
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2015-3-29
得分:0 
回复 楼主 wyslsm

网上复制的代码,数据库根据网上介绍制作,为什么第二个选择菜单没有数据?(第一个选择菜单有数据)

请教




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



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




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

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