新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > Web开发 > Asp教程 > 正文:基于数据库的三级菜单实现(二级同理)

基于数据库的三级菜单实现(二级同理)

新客网 XKER.COM 2005-04-21 来源: 收藏本文
  
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0"  class="font">
  <tr> 
      <td height="44" align="right">产品编号:</td>
      <td align="left"><input name="pro_id"></td>
    </tr>
   <tr> 
      <td height="41" align="right"> 
        <%
set rs=server.CreateObject("adodb.recordset")
sq="select * from pro_big_part"
rs.open sq,conn,1,1%>
        <select  name="big_part"  onChange="ld();ld2()">
          <option value="" selected>选择一级目录</option>
          <%while not rs.eof%>
          <option value="<%=rs("big_part")%>"><%=rs("big_part")%></option>
          <%rs.movenext
wend
rs.close%>
        </select> </td>
      <td align="left"> <select  name="small_part" onChange="ld2()">
          <option value="" selected>选择二级目录</option>
        </select> &nbsp; <select  name="thr_part">
          <option value="" selected>选择三级目录</option>
        </select> 
        <%sql="select * from pro_small_part"
rs.open sql,conn,1,1
num=rs.recordcount
str=""
for i=1 to rs.recordcount
str=str&rs("big_part")&"-"&rs("small_part")&","
if rs.eof then exit for
rs.movenext
next
rs.close
%>
<%sql="select * from pro_thr_part"
rs.open sql,conn,1,1
num2=rs.recordcount
str2=""
for i=1 to rs.recordcount
str2=str2&rs("small_part")&"-"&rs("thr_part")&","
if rs.eof then exit for
rs.movenext
next
rs.close
%>
<!--下面是实现动态改变下一级菜单的脚本代码-->
        <script  LANGUAGE="javascript">
arr="<%=str%>".split(",");
a=arr.length
ar=new Array()
for (i=0;i<a;i++){
  ar[i]=arr[i].split("-");
}
onecount=ar.length;
arr2="<%=str2%>".split(",");
a2=arr2.length
ar2=new Array()
for (i=0;i<a2;i++){
  ar2[i]=arr2[i].split("-");
}
onecount2=ar2.length;
function  ld() {
  document.form1.small_part.length=0
  lid=form1.big_part.value;       
  for  (i=0;i<onecount;i++)  { 
    if  (ar[i][0]  ==  lid) {
   document.form1.small_part.options.add(new Option(ar[i][1],  ar[i][1]));    
    }    
  }   
}   
function  ld2() {
  document.form1.thr_part.length=0
  lid2=form1.small_part.value;       
  for  (i=0;i<onecount2;i++)  { 
    if  (ar2[i][0]  ==  lid2) {
   document.form1.thr_part.options.add(new Option(ar2[i][1],  ar2[i][1]));    
    }    
  }   
}   
</script></td>
    </tr></table>
收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐