日期:2014-05-17  浏览次数:21051 次

asp三级联动菜单问题
VBScript code

<!--#include file="inc/config.asp"-->
<%call connectiondatabase("./")%>
<!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=gb2312" />
<title>多级联动下拉菜单</title>
</head>
<!--
'++++++++++++对数据库的注释区-lxq所写+++++++++++
'products_class 表为一个记录地区的表
'其中的字段分别的id(自动编号),title_cn(分类名称),fatherID(父类ID)
'当fatherID为0的时候,则说明此地区为顶级类
-->
<%sql = "select *  from products_class order by id desc"
set rs=server.createobject("ADODB.Recordset")
rs.open sql,conn,1,3%>
<script language = "JavaScript">
var onecount1;
onecount1=0;
subcat1 = new Array();
<%count = 0
do while not rs.eof%>
subcat1[<%=count%>] = new Array("<%= trim(rs("title_cn"))%>","<%= trim(rs("fatherID"))%>","<%= trim(rs("id"))%>");
        <%count = count + 1
        rs.movenext
        loop
        rs.close
        set rs=nothing%>
onecount1=<%=count%>;

function change_one(addone)
    {
    document.all.etwo_id.length = 0; 

    var eone_id=eone_id;
    var i;
    document.all.etwo_id.options[0] = new Option('请选择','');
    for (i=0;i < onecount1; i++)
        {
            if (subcat1[i][1] == addone)
            { 
                document.all.etwo_id.options[document.all.etwo_id.length] = new Option(subcat1[i][0], subcat1[i][2]);
            }        
        }
        
    }
</script>
<body>
<table width="500" border="0" cellspacing="5" cellpadding="0">
  <tr>
    <td width="373"><select name="eone_id" onChange="change_one(document.all.eone_id.options[document.all.eone_id.selectedIndex].value)">
<option value="" selected>请选择</option>
                    <%
set rs=server.createobject("ADODB.Recordset")
sql="select *  from products_class where fatherID=0 order by id asc "
rs.open sql,conn,1,3
if not rs.eof then 
do while not rs.eof%>
<option value="<%=rs("id")%>"  <%if eone_id=trim(rs("id")) then response.Write("selected='selected'") end if%> ><%=rs("title_cn")%></option>
<%rs.movenext
loop
end if
%> 
</select>
      <select name="etwo_id" id="etwo_id">
      <option selected value="0">请选择</option>
      </select>      </td>
  </tr>
</table>
</body>
</html>




这是个2级联动,求高手帮忙改出三级联动,此代码完美运行

------解决方案--------------------
给你现成的

<script language="JavaScript">
<!--
<%
'二级数据保存到数组
Dim count2,rsClass2,sqlClass2
set rsClass2=server.createobject("adodb.recordset")
sqlClass2="select * from venshop_nsort order by nsort_xu asc" 
rsClass2.open sqlClass2,conn,1,1
%>
var subval2 = new Array();
//数组结构:一级根值,二级根值,二级显示值
<%
count2 = 0
do while not rsClass2.eof
%>
subval2[<%=count2%>] = new Array('<%=rsClass2("sort_id")%>','<%=rsClass2("nsort_id")%>','<%=rsClass2("nsort_name")%>')
<%
count2 = count2 + 1
rsClass2.movenext
loop
rsClass2.close
%>

<%
'三级数据保存到数组
Dim count3,rsClass3,sqlClass3
set rsClass3=server.createobject("adodb.recordset")
sqlClas