带有数据库的动态级联菜单
这是一个带有数据库的动态级联菜单,搞了好久都没搞出来,在经典有人帮我贴出来了,我稍微修改了一下收藏在这里,希望和大家一起分享!
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%> <!--#include file="Connections/connMenu.asp" --> <% Dim RecMain Dim RecMain_numRows Set RecMain = Server.CreateObject("ADODB.Recordset") RecMain.ActiveConnection = MM_connMenu_STRING RecMain.Source = "SELECT * FROM main" RecMain.CursorType = 0 RecMain.CursorLocation = 2 RecMain.LockType = 1 RecMain.Open() RecMain_numRows = 0 %> <% Dim RecSub Dim RecSub_numRows Set RecSub = Server.CreateObject("ADODB.Recordset") RecSub.ActiveConnection = MM_connMenu_STRING RecSub.Source = "SELECT * FROM sub" RecSub.CursorType = 0 RecSub.CursorLocation = 2 RecSub.LockType = 1 RecSub.Open() RecSub_numRows = 0 %> <html> <head> <title>动态级联菜单</title> </head> <body> <form name="form1"> <select name="MainMenu" id="MainMenu" onchange="redirect(this.options.value)"> <option value="0">--请选择--</option> <% While (NOT RecMain.EOF) %> <option value="<%=(RecMain.Fields.Item("main_id").Value)%>"><%=(RecMain.Fields.Item("main_name").Value)%></option> <% RecMain.MoveNext() Wend If (RecMain.CursorType > 0) Then RecMain.MoveFirst Else RecMain.Requery End If %> </select> <select name="SubMenu" id="SubMenu"> <option value="0">--请选择--</option> </select> </form> <script> <!-- var temp=document.form1.SubMenu function redirect(x){ var i i=0 <%while not RecSub.eof %> cnt=<%=RecSub("main_id")%> if (cnt==x){ temp.options[i]=new Option("<%=RecSub("sub_name")%>","<%=RecSub("sub_id")%>") i=i+1 } <% RecSub.movenext Wend %> } --> </script> </body> </html> <% RecMain.Close() Set RecMain = Nothing %> <% RecSub.Close() Set RecSub = Nothing %>
看上去代码好像不少,其实大部分是DW中的"绑定"和"服务器行为"自动生成的.简单实用!
原地址:http://www.5dblog.com/user1/zzj/?id=59850 有一个附件为:undefined