http://expert.csdn.net/Expert/topic/1476/1476173.xml?temp=.3475305

解决方案 »

  1.   

    你自己再发挥一下:<form name=form1>
    <select name=province onchange="cityName(this.selectedIndex)">
      <option value="">请选择省名</option>
    </select><select name=city>
      <option value="">请选择城名</option>
    </select>
    </form><script language=javascript>
    var city1 = ["杭州", "宁波", "温州", "绍兴", "金华", "湖州"];
    var city2 = ["南京", "苏州", "无锡", "常州", "镇江", "徐州"];
    var city3 = ["合肥", "翕县", "黄山", "祁门", "休宁"];
    var city4 = ["南昌", "九江", "赣州", "上饶", "新余", "景德镇"]; 
    var provinceName = ["浙江", "江苏", "安徽", "江西"];function province()
    {    var e = document.form1.province;
        for (var i=0; i<provinceName.length; i++)
           e.options.add(new Option(provinceName[i], provinceName[i]));
    }
    function cityName(n)
    {
        var e = document.form1.city;
        for (var i=e.options.length; i>0; i--)  e.remove(i);
        if (n == 0) return;
        var a = eval("city"+ n); //得到城市的数组名
        for (var i=0; i<a.length; i++) e.options.add(new Option(a[i], a[i]));
    }
    function window.onload()
    {
        province(); //初始时给省名下拉菜单赋内容
    }
    </script>
      

  2.   

    两种方法,一次就是开始从数据库中全部读出来,记录在javascript定义的变量中,由javascript来调用和生成。另一种方法,就是选择一个下拉列表,重载该页面,用程序读出数据生成下拉列表。
      

  3.   

    这是我自己写的
    1.asp
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>两级连动数据库版</title>
    <!--
    数据库名 test.mdb
    表结构(dbselect):id(自动编号) parent(text) sub(text)
    -->
    </head>
    <script>
    function go(s){
    if(s.selectedIndex==0){
    document.getElementById('s2').options.length=0;
    document.getElementById('s2').add(new Option("请选择"));
    return;
    }
    hidfrm.location.href='2.asp?parent='+s.value
    }
    </script>
    <body>
    <%  dim conn,rs
     set conn = Server.CreateObject("ADODB.Connection")
         conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.mappath("test.mdb") & ";Persist Security Info=False"
       set rs = Server.CreateObject("ADODB.Recordset")
         rs.Open "select parent from dbselect group by parent",conn,1,3
    %>
    <select id="s1" onchange="go(this)">
    <option>请选择</option>
    <%do while not rs.eof%>
    <option value="<%=rs("parent")%>"><%=rs("parent")%></option>
    <%rs.movenext
    loop
    set rs=nothing
    %>
    </select>
    <select id="s2">
    <option>请选择</option>
    </select>
    <iframe src="2.asp" width=0 height=0 name=hidfrm></iframe>
    </body>
    </html>2.asp
    <% if  request.querystring("parent")<>"" then
    dim conn,rs
     set conn = Server.CreateObject("ADODB.Connection")
         conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.mappath("test.mdb") & ";Persist Security Info=False"
       set rs = Server.CreateObject("ADODB.Recordset")
         rs.Open "select sub from dbselect where parent='"&request.querystring("parent")&"'",conn,1,3
    if not rs.eof then
    %>
    <script>
    var s=parent.document.getElementById("s2")
    s.options.length=0
    <%do while not rs.eof%>
    s.add(new Option("<%=rs("sub")%>","<%=rs("sub")%>"))
    <%
    rs.movenext
    loop
    %>
    </script>
    <%
    end if
    end if
    %>
      

  4.   

    <!-- 数据库结构 两个字段 provinceName(省名)  cityName(城市名) -->
    <!-- #include file="connection.asp" -->
    <script language=javascript>
    <%
    dim RS
        Set RS = Server.CreateObject("ADODB.Recordset")
        RS.open "SELECT * FROM tableName ORDER BY provinceName DESC", Conn, 0, 1dim provinceName '省名
    dim provinceList '记录所有的省名, 最后输出到JS里组成省名数组
    dim cityList     '记录某个省的所有城市名, 最后输出到JS里组成城市名数组
    dim cityIndex    'JS的city数组名与省名下拉框的索引对应
        cityIndex = 1    do while not RS.eof
            if  isEmpty(provinceName) then
                cityList = cityList & chr(34) & Trim(RS("cityName")) & chr(34) &","
                provinceName = Trim(RS("provinceName"))
            else
                if  provinceName<>Trim(RS("provinceName")) then
                    provinceList = provinceList & chr(34) & provinceName & chr(34) &","
                    if not isEmpty(cityList) then Response.write "var city"& cityIndex &_
                    " = ["& Left(cityList, Len(cityList)-1) &"];"& VBCrLf
                    '输出每个省所对应的城市名的列表并组成JS的数组, 数组形式参考下面的实例
                    cityIndex = cityIndex + 1
                    cityList = ""
                end if
                provinceName = Trim(RS("provinceName"))
                cityList = cityList & chr(34) & Trim(RS("cityName")) & chr(34) &","
                '将每个省里的所有城市名组成一串字串
            end if
            RS.movenext
        loop    if not isEmpty(cityList) then
            Response.write "var city"& cityIndex &" = ["& Left(cityList, Len(cityList)-1) &"];"& VBCrLf
        end if
        if not isEmpty(provinceName) then
            provinceList = provinceList & chr(34) & provinceName & chr(34) &","
            Response.write "var provinceName = ["& Left(provinceList, Len(provinceList)-1) &"];"
            '输出省名字串并组成省名的JS数组, 形式见下实例
        end if    RS.close    : Set RS=nothing
        Conn.close  : Set Conn=nothing
    %>
    </script><form name=form1>
    <select name=province onchange="cityName(this.selectedIndex)">
      <option value="">请选择省名</option>
    </select><select name=city>
      <option value="">请选择城名</option>
    </select>
    </form><script language=javascript>/* 若要直接看下拉框联动效果的话, 将这段被注释的代码起用, 且上面的那段ASP注释即可
    var city1 = ["杭州", "宁波", "温州", "绍兴", "金华", "湖州"];
    var city2 = ["南京", "苏州", "无锡", "常州", "镇江", "徐州"];
    var city3 = ["合肥", "翕县", "黄山", "祁门", "休宁"];
    var city4 = ["南昌", "九江", "赣州", "上饶", "新余", "景德镇"]; 
    var provinceName = ["浙江", "江苏", "安徽", "江西"];
    //你在ASP输出的页面里应该看到如上这般的JS数组, 能看到则表示成功
    */
    function province()
    {    var e = document.form1.province;
        for (var i=0; i<provinceName.length; i++)
           e.options.add(new Option(provinceName[i], provinceName[i]));
    }
    function cityName(n)
    {
        var e = document.form1.city;
        for (var i=e.options.length; i>0; i--)  e.remove(i);
        if (n == 0) return;
        var a = eval("city"+ n); //得到城市的数组名
        for (var i=0; i<a.length; i++) e.options.add(new Option(a[i], a[i]));
    }
    function window.onload()
    {
        province(); //初始时给省名下拉菜单赋内容
    }
    </script>
      

  5.   

    <script language="javascript">
    function ss()
    {
      var ss=document.formname.sel.value;
      document.formname.temp.value=ss;
      formname.submit;
    }
    </script>
    在本页执行,只需要用request("temp")就能够将原来的内容重新获得
    然后通过判断语句就能用selected属性使原来的内容不变了
    <form name=formname method=post action="">
    <select name="sel" onchange="ss()">
      <option value="DepID">xxx</option>
      <option value="DepID">xxx</option>
      <option value="DepID">xxx</option>
      <option value="DepID">xxx</option>
    </select>
    <input type="hidden" name="temp" value="">
    </form>
      

  6.   

    关注三级连动中..........................#~~~~~~&&&~~~~****
      

  7.   

    http://www.sayee.com/cloudchen/js/thirdChange.htm
      

  8.   

    http://expert.csdn.net/Expert/topic/2222/2222653.xml?temp=5.759829E-02
    去这里up我给你分