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

80酷酷网    80kuku.com

  菜单|数据|数据库  
<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>   <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;&nb

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: