首页
印 像 新 闻 系 统
网站首页 公告信息 编程实例 PHP函数 摄影无界 全景展示 我的作品 意见专栏
 

二ASP和JS级联动分类

【2006年01月06日 13:28:08】 【阅读:次】 【字体:大 中 小 默认】 【背景:#换背景 #换背景 #换背景 #换背景 #换背景 #换背景 #换背景 默认】

我用过的二级联动分类:

表名分别为:

articlesaid

articlesbid

表名和字段根据需求自行修改!

<%

dim count
set rsn=server.createobject("adodb.recordset")
rsn.open "select * from [articlesbid] order by [row]",conn,1,1
%>
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
<%
   count = 0
   do while not rsn.eof
%>
subcat[<%=count%>] = new Array("<%= trim(rsn("Nclass"))%>","<%= rsn("classid")%>","<%= rsn("Nclassid")%>");
<%
       count = count + 1
       rsn.movenext
   loop
   rsn.close
%>
onecount=<%=count%>;

function changelocation(locationid)
    {
    document.myform.Nclassid.length = 0;

    var locationid=locationid;
    var i;
    for (i=0;i < onecount; i++)
        {
            if (subcat[i][1] == locationid)
            { //这句不是很理解
             document.myform.Nclassid.options[document.myform.Nclassid.length] = new Option(subcat[i][0], subcat[i][2]);
            }       
        }
    }   

 

 

<%
        rsn.open "select * from [articlesaid] order by [row]",conn,1,1
     if rsn.eof and rsn.bof then
        response.write "请先添加栏目。"
        response.end
     else%>
  <select name="anclassid" size="1" id="anclassid" onChange="changelocation(document.myform.anclassid.options[document.myform.anclassid.selectedIndex].value)">
          <option selected value="<%=rsn("classid")%>"><%=trim(rsn("class"))%></option>
          <%dim selclass
            selclass=rsn("classid")
            rsn.movenext
            do while not rsn.eof%>
          <option value="<%=rsn("classid")%>"><%=trim(rsn("class"))%></option>
          <%
              rsn.movenext
            loop
     end if
        rsn.close%>
        </select>
   <select name="Nclassid">
          <%rsn.open "select * from [articlesbid] where [classid]="&selclass ,conn,1,1
        if not(rsn.eof and rsn.bof) then%>
          <option selected value="<%=rsn("Nclassid")%>"><%=trim(rsn("Nclass"))%></option>
          <%rsn.movenext
          do while not rsn.eof%>
          <option value="<%=rsn("Nclassid")%>"><%=trim(rsn("Nclass"))%></option>
          <% rsn.movenext
          loop
         end if
         rsn.close
         set rsn = nothing%>
        </select>


(『印像空间』 【本文来源:『学习笔记』】 【作者:未知】 【录入:留印】)
限200字,剩余 字
关 键 字:
    
搜索条件: