![]() |
![]() |
![]() |
![]() |
![]() ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() ![]() |
供应求购 | 免费商铺 | 商业资讯 | 库存二手 | 黄页大全 | 生活贴吧 | 房屋租售 | 招聘求职 | 婚恋交友 | 自助广告 |
ASP级联下拉菜单代码 | ||
发布时间:2010/12/9 11:59:11 发布人:网络游民 点击:173 | ||
-------------------------------------------------------------------------------- 本代码实现二级级联下拉菜单效果,在网站后台,网上商城等多处用到,本代码简单易改,几乎不用修改,直接复制过去就可用。 数据库结构:bigclass(大类表名) bigclassid(自动编号),bigclassname(文本) smallclass(小类表名) smallclassid(自动编号) smallclassname(文本) bigclassid(数字) <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>ASP+JavaScript+数据库 级联下拉菜单</title> <style> table{border: #00215a 1px dashed;} td{font-size:12px;} select{ font-size:9pt; border-style:solid; border-width:1; cursor:default; color:#03326B; background-color:#FFFFFF; height:16px; } </style> <%'从小类表中取出数据 set rs=server.CreateObject("adodb.recordset") sql="select * from smallclass " rs.open sql,conn,1,1 %> <script language="JavaScript"> var num; //定义数组 var calArray=new Array(); <% dim j j=0 do while not rs.eof %> //将小类表中的所有相关记录存到数组calArray的对应元素中。 calArray[<%=j%>]=new Array("<%=rs("smallclassid")%>","<%=rs("smallclassname")%>","<%=rs("bigclassid")%>"); <% j=j+1 rs.movenext loop rs.close set rs=nothing %> //给num赋值为记录总数 num=<%=j%> function givevalue(myvalue){ /*当选择大类列表的值不为空时首先清空小类下拉列表的所有项目。不然小类列表中的项目会叠加的。 同时也是初始化 options 的值为0 */ document.from1.small_class_select.length = 0; //循环写出请求的大类所对应的小类。 for (i=0;i < num; i++) { if (calArray[i][2] == myvalue) { document.from1.small_class_select.options[document.from1.small_class_select.length] = new Option(calArray[i][1], calArray[i][0],"",""); /*定义新的Option对象并赋值。options的索引值从0开始。new Option对象有4个属性,对应分别是:文本串、value、defaultSelect、selected。在这里只用了第一个和第二个。*/ } } } </script> </head> <body> <% dim rs,sql,noclass %> <table width="594" height="50" border="0"> <tr> <td width="586" valign="middle"><form name="from1" method="post" action=""> <select name="big_class_select" onChange="givevalue(document.from1.big_class_select.options[document.from1.big_class_select.selectedIndex].value)"> <% dim firstid set rs=server.CreateObject("adodb.recordset") sql="select * from bigclass order by bigclassid" rs.open sql,conn,1,1 if rs.eof or rs.bof then noclass=1 %> <option selected>还没有添加大类</option> <% else rs.movefirst firstid=rs("bigclassid") '在没有选择大类(页面刚载入)时要载入的大类。 %> <option value="<%=rs("bigclassid")%>" selected><%=trim(rs("bigclassname"))%></option> <% rs.movenext do while not rs.eof %> <option value="<%=rs("bigclassid")%>"><%=trim(rs("bigclassname"))%></option> <% rs.movenext loop end if rs.close set rs=nothing %> </select> <select name="small_class_select"> <%if noclass=1 then%> <option value="" selected>没有小类</option> <% else '在没有选择大类(页面刚载入)时要载入的小类,要跟默认的大类对应。 set rs=server.CreateObject("adodb.recordset") sql="select * from smallclass where bigclassid="&firstid rs.open sql,conn,1,1 if rs.eof or rs.bof then %> <option value="" selected>没有小类</option> <% else do while not rs.eof %> <option value="<%=rs("smallclassid")%>"><%=trim(rs("smallclassname"))%></option> <% rs.movenext loop end if rs.close set rs=nothing end if %> </select> </form></td> </tr> </table> <% conn.close set conn=nothing %> </body> </html> 本文来自: 免费资源收集网(down.0857w.com) 详细出处参考:http://down.0857w.com/article/155.htm |
||
![]() |
![]() |
![]() |
※ | 发布回复 | ↓请遵循123发布网同城生活贴吧/论坛发帖规则;↓寻一夜情、包养、招嫖类信息的一律全部删除,并报公安备案↓ | |
|
![]() |
![]() |
网站首页 | 关于我们 | 广告业务 | 关于VIP | 免责声明 | 联系我们 | 设为首页 | 加入收藏 | 意见反馈 | 网站建设 |
123发布网 版权所有 www.123fbw.com 联系电话:18331151646 QQ:1016964448
CopyRight © 2007-2016 All Right Reserved 联系站长 津ICP备10002728号 统计: |