日期:2014-05-17 浏览次数:21147 次
<!--#include file="inc/config.asp"--> <%call connectiondatabase("./")%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>多级联动下拉菜单</title> </head> <!-- '++++++++++++对数据库的注释区-lxq所写+++++++++++ 'products_class 表为一个记录地区的表 '其中的字段分别的id(自动编号),title_cn(分类名称),fatherID(父类ID) '当fatherID为0的时候,则说明此地区为顶级类 --> <%sql = "select * from products_class order by id desc" set rs=server.createobject("ADODB.Recordset") rs.open sql,conn,1,3%> <script language = "JavaScript"> var onecount1; onecount1=0; subcat1 = new Array(); <%count = 0 do while not rs.eof%> subcat1[<%=count%>] = new Array("<%= trim(rs("title_cn"))%>","<%= trim(rs("fatherID"))%>","<%= trim(rs("id"))%>"); <%count = count + 1 rs.movenext loop rs.close set rs=nothing%> onecount1=<%=count%>; function change_one(addone) { document.all.etwo_id.length = 0; var eone_id=eone_id; var i; document.all.etwo_id.options[0] = new Option('请选择',''); for (i=0;i < onecount1; i++) { if (subcat1[i][1] == addone) { document.all.etwo_id.options[document.all.etwo_id.length] = new Option(subcat1[i][0], subcat1[i][2]); } } } </script> <body> <table width="500" border="0" cellspacing="5" cellpadding="0"> <tr> <td width="373"><select name="eone_id" onChange="change_one(document.all.eone_id.options[document.all.eone_id.selectedIndex].value)"> <option value="" selected>请选择</option> <% set rs=server.createobject("ADODB.Recordset") sql="select * from products_class where fatherID=0 order by id asc " rs.open sql,conn,1,3 if not rs.eof then do while not rs.eof%> <option value="<%=rs("id")%>" <%if eone_id=trim(rs("id")) then response.Write("selected='selected'") end if%> ><%=rs("title_cn")%></option> <%rs.movenext loop end if %> </select> <select name="etwo_id" id="etwo_id"> <option selected value="0">请选择</option> </select> </td> </tr> </table> </body> </html>