注册 登录
编程论坛 ASP技术论坛

[求助]求做一个三级下拉列表框

suyongtao 发布于 2005-08-08 10:48, 6803 次点击
我找到了二级的,,就是一个产品发布系统的类别选择的下拉列表,一选定大类,小类自动被选,
我现在想要个三级的,就是选定大类小类自动出现所有属于这个大类的小类,然后在这里面选定小类以后,三级类别,所有属于这个小类的所以三级类被自动选定,类似小类的功能..
我现在把二级类的代码和函数公布一下,大家帮忙改一下..
36 回复
#2
suyongtao2005-08-08 10:51

var onecount; onecount=0; subcat = new Array(); <% count = 0 do while not rs.eof %> subcat[<%=count%>] = new Array("<%= trim(rs("sorts"))%>","<%= rs("categoryid")%>","<%= rs("sortsid")%>"); <% count = count + 1 rs.movenext loop rs.close %> onecount=<%=count%>;

function changelocation(locationid) { document.myform.sortsid.length = 0;

var locationid=locationid; var i; for (i=0;i < onecount; i++) { if (subcat[i][1] == locationid) { document.myform.sortsid.options[document.myform.sortsid.length] = new Option(subcat[i][0], subcat[i][2]); } } } <% rs.open "select * from category order by categoryorder",conn,1,1 if rs.eof and rs.bof then response.write "没有东西!" response.end else %> <select name="categoryid" size="1" id="categoryid" onChange="changelocation(document.myform.categoryid.options[document.myform.categoryid.selectedIndex].value)"> <option selected value="<%=rs("categoryid")%>"><%=trim(rs("category"))%></option> <% dim selclass selclass=rs("categoryid") rs.movenext do while not rs.eof %> <option value="<%=rs("categoryid")%>"><%=trim(rs("category"))%></option> <% rs.movenext loop end if rs.close %> </select> 所属小类 <select name="sortsid"> <% rs.open "select * from sorts where categoryid="&selclass ,conn,1,1 if not(rs.eof and rs.bof) then %> <option selected value="<%=rs("sortsid")%>"><%=rs("sorts")%></option> <% rs.movenext do while not rs.eof %> <option value="<%=rs("sortsid")%>"><%=rs("sorts")%></option> <% rs.movenext loop end if rs.close rs.open "select * from TimesProList",conn,1,1 %> </select> 大家帮忙改一下..

#3
suyongtao2005-08-08 10:57
这是图片
只有本站会员才能查看附件,请 登录


[此贴子已经被作者于2005-8-8 10:58:45编辑过]


#4
islet2005-08-08 11:22
java脚本不熟 要是纯asp的你也会做
#5
suyongtao2005-08-08 14:34
汗,,那个客户不要.
#6
无根泉2005-08-08 14:57
你用ASP写一个,然后用
iframe弄过去,这样你不说谁知道呀,
我现在整二级互联就这样做!
#7
islet2005-08-08 15:18
客户懂得挺多啊

石家庄的客户真牛 不去那混~!!
#8
islet2005-08-08 15:23
[转载] <% set rs=server.createobject("adodb.recordset") rs.open"select * from class_two",conn,1,1 %> ‘---------以上是查询出第一级下拉列表的内容----- ’---------以下是用JS来控制程序-------------- <script language = "JavaScript"> var onecount; //定义onecount对像 onecount=0;//初始值为0 subcat = new Array(); //SUBCAT对像是一个新的数组 <% count = 0 '定义count对像初始值为0 do while not rs.eof '循环表头到表尾 %> subcat[<%=count%>] = new Array("<%=rs("class_two_text")%>","<%=trim(rs("class_one"))%>","<%=trim(rs("class_two"))%>"); //以上为重点内容,对像数组(subcat[count对像值])= 新数组内容('字段名0','字段名1','字段名2')记住要对应 <% count = count + 1 '循环count一次,COUNT的值加1 rs.movenext loop rs.close %> onecount=<%=count%>; function changelocation(locationid) { document.form.class_two.length = 0; var locationid=locationid; var i; for (i=0;i < onecount; i++) { if (subcat[1] == locationid) { document.form.class_two.options[document.form.class_two.length] = new Option(subcat[0], subcat[2]); } } } </script> <% set rs=server.CreateObject("adodb.recordset") rs.open "select * from Class_one" ,conn,1,1 if rs.eof then response.Write"暂无产品一类名称" else%> 产品一类 <select name="class_one" id="class_one" onChange="changelocation(document.form.class_one.options[document.form.class_one.selectedIndex].value)"> <%do while not rs.eof%> <option value="<%=rs("class_one")%>"><%=rs("class_one_text")%></option> <%rs.movenext loop end if %> </select> 产品二类 <select name="class_two" onChange="three(document.form.class_one.value,document.form.class_two.options[document.form.class_two.selectedIndex].value)"> <option value="请选择条件" selected>请选择条件</option> </select> <% set rs=server.createobject("adodb.recordset") rs.open"select * from class_three",conn,1,1 %> <script language = "JavaScript"> var twocount; twocount=0; subthree = new Array(); <% countb = 0 do while not rs.eof %> subthree[<%=countb%>] = new Array("<%=rs("class_three_text")%>","<%=trim(rs("class_one"))%>","<%=trim(rs("class_two"))%>","<%=trim(rs("class_three"))%>"); <% countb = countb + 1 rs.movenext loop rs.close %> twocount=<%=countb%>; function three(threeid,threeid2) { document.form.class_three.length = 0; var threeid=threeid; var threeid2=threeid2; var i; for (i=0;i < twocount; i++) { if ((subthree[1] == threeid) & (subthree[2] == threeid2)) { document.form.class_three.options[document.form.class_three.length] = new Option(subthree[0], [转自:飞腾设计网 www.feitec.com]subthree[3]); } } } </script> 产品三类 <select name="class_three" id="class_three"> <option value="0" selected>请选择条件</option> </select> [转自:飞腾设计网 www.feitec.com]
#9
suyongtao2005-08-08 15:48
谢了,,哥们.
#10
yms1232005-08-08 21:00
https://bbs.bc-cn.net/bbs/dispbbs.asp?BoardID=10&ID=24520 我这里写过现成的,这个JavaScript虽然是两级的但是。稍加更改就可以做成多级的,而且非常简单。
#11
yms1232005-08-08 21:02
不用的时候不说回复,用的时候选求助。
#12
suyongtao2005-08-09 11:17
建议收录到居顶问题贴中
#13
hxfly2005-08-09 11:22
应该已经收录了吧
#14
suyongtao2005-08-18 09:06
顶一下..
#15
islet2005-08-18 13:35
网上的我也看不好
我写了一个静态的 相应改成ASP读数据库的就行了
先测试一下
[CODE]&lt;script language="JavaScript"&gt;
function bb(num){
city = new Array();
city[1]= new Array("唐山市","1","1");
city[2]= new Array("石家庄","2","1");
city[3]= new Array("营口市","3","2");
city[4]= new Array("沈阳市","4","2");
//把数组的值用数据库读出
document.form1.s1.length = 0;
document.form1.s2.length = 0;
document.form1.s2.options[0]= new Option("还没有县","0");
document.form1.s1.options[0]= new Option("请选择市","0");
j=1;
for(i=1;i&lt;=4;i++)
{ if(city[i][2]==num)
{document.form1.s1.options[document.form1.s1.length]= new Option(city[i][0],city[i][1]);}
j++}
}
function cc(num){
city = new Array();
city[1]= new Array("唐山路北区","1","1");
city[2]= new Array("唐山古冶区","2","1");
city[3]= new Array("石家庄正定","3","2");
city[4]= new Array("石家庄新集","4","2");
city[5]= new Array("营口站前区","5","3");
city[6]= new Array("营口西市区","6","3");
city[7]= new Array("沈阳市区","7","4");
city[8]= new Array("沈阳三好街","8","4");
//把数组的值用数据库读出
document.form1.s2.length = 0;
document.form1.s2.options[0]= new Option("请选择县","0");
j=1;
for(i=1;i&lt;=8;i++)
{ if(city[i][2]==num)
{document.form1.s2.options[document.form1.s2.length]= new Option(city[i][0],city[i][1]);}
j++}
}
&lt;/script&gt;
&lt;body&gt;
&lt;form name="form1" method="post" action=""&gt;
&lt;!--form1.ss的值用数据库读出--&gt;
  &lt;select name="ss" onChange="bb(document.form1.ss.options[document.form1.ss.selectedIndex].value)"&gt;
   &lt;option value="0"&gt;请选择省&lt;/option&gt;
&lt;option value="1"&gt;河北省&lt;/option&gt;
&lt;option value="2"&gt;辽宁省&lt;/option&gt;
  &lt;/select&gt;
  &lt;select name="s1" onChange="cc(document.form1.s1.options[document.form1.s1.selectedIndex].value)"&gt;
  &lt;/select&gt;
  &lt;select name="s2" id="s2"&gt;
  &lt;/select&gt;
&lt;/form&gt;
&lt;/body&gt;
[/CODE]


以下是代码
&lt;script language="JavaScript"&gt;
function bb(num){
city = new Array();
city[1]= new Array("唐山市","1","1");
city[2]= new Array("石家庄","2","1");
city[3]= new Array("营口市","3","2");
city[4]= new Array("沈阳市","4","2");
//把数组的值用数据库读出
document.form1.s1.length = 0;
document.form1.s2.length = 0;
document.form1.s2.options[0]= new Option("还没有县","0");
document.form1.s1.options[0]= new Option("请选择市","0");
j=1;
for(i=1;i&lt;=4;i++)
{ if(city[i][2]==num)
{document.form1.s1.options[document.form1.s1.length]= new Option(city[i][0],city[i][1]);}
j++}
}
function cc(num){
city = new Array();
city[1]= new Array("唐山路北区","1","1");
city[2]= new Array("唐山古冶区","2","1");
city[3]= new Array("石家庄正定","3","2");
city[4]= new Array("石家庄新集","4","2");
city[5]= new Array("营口站前区","5","3");
city[6]= new Array("营口西市区","6","3");
city[7]= new Array("沈阳市区","7","4");
city[8]= new Array("沈阳三好街","8","4");
//把数组的值用数据库读出
document.form1.s2.length = 0;
document.form1.s2.options[0]= new Option("请选择县","0");
j=1;
for(i=1;i&lt;=8;i++)
{ if(city[i][2]==num)
{document.form1.s2.options[document.form1.s2.length]= new Option(city[i][0],city[i][1]);}
j++}
}
&lt;/script&gt;
&lt;body&gt;
&lt;form name="form1" method="post" action=""&gt;
&lt;!--form1.ss的值用数据库读出--&gt;
  &lt;select name="ss" onChange="bb(document.form1.ss.options[document.form1.ss.selectedIndex].value)"&gt;
   &lt;option value="0"&gt;请选择省&lt;/option&gt;
&lt;option value="1"&gt;河北省&lt;/option&gt;
&lt;option value="2"&gt;辽宁省&lt;/option&gt;
  &lt;/select&gt;
  &lt;select name="s1" onChange="cc(document.form1.s1.options[document.form1.s1.selectedIndex].value)"&gt;
  &lt;/select&gt;
  &lt;select name="s2" id="s2"&gt;
  &lt;/select&gt;
&lt;/form&gt;
&lt;/body&gt;

[此贴子已经被作者于2005-8-18 14:54:23编辑过]


#16
hxfly2005-08-18 14:26
不错不错
简练
#17
suyongtao2005-08-18 14:27
强,,顶..
#18
hxfly2005-08-18 14:30
有一个小问题


就是当第一级改变以后应该把第二,三级归位(好象这个第三级没有归位)

[此贴子已经被作者于2005-8-18 14:31:27编辑过]


#19
suyongtao2005-08-18 14:34
就是,选了一第级时,第三级好像没有归位或者出现相应的情况,,
#20
caiyakang2005-08-18 14:54
顶,虽然我还没用过
#21
islet2005-08-18 14:55
改好了
#22
hxfly2005-08-18 15:00
收藏了
#23
suyongtao2005-08-18 16:04
我的这个类别就用三个表组成的,
一级类的表名是 category  类别id 是categoryid
二级类的表名是 sortsid     类别id 是sortsid
三级类的表名是 san         类别id  是sanid
他们是通过类别的id联系在一起的,帮我改一下吧,改成三级类别的那个,谢谢了,,
#24
suyongtao2005-08-18 16:09
类别的名称它对应的表名一样.
#25
suyongtao2005-08-18 16:59
#26
islet2005-08-18 17:23
下次去石家庄有着落了
[URL=http://www.]数据库三级联动点击查看[/URL]
#27
suyongtao2005-08-18 17:30
呵呵,没问题,,
#28
yms1232005-08-20 11:29
15楼的写的也还算简单一些,用new options的办法来改变列表数组的值。不过个人觉得三级菜单也就是要有一个数据外键作判断,第一级菜单数据库里的项目应该是主键。第二级则是对应表的外键。第三级同样道理是第二级外键的对应外键。反正我写的以id为标准的多级下拉菜单的判断原理就是这个样子,利用关系型数据库主外键的原理。
#29
a8a122006-12-04 17:16
哦   
#30
gdk20062006-12-05 13:13
收下了!回去研究研究,谢过各位了!
#31
a8a122006-12-16 10:17
呵呵
#32
zhongshi2006-12-16 10:56
哈哈....楼上的好强
#33
tago2006-12-20 15:21
真的很好!请问那个嵌套的(多级)菜单怎么写的?
之前用层实现过二层菜单,但是有很大的问题,在不同的显示器上显示就完全变了!
#34
islet2006-12-20 15:36
那是你css学得不好
#35
lq73506842006-12-31 15:03
真是牛比啊,又学了一招,顶了.
#36
heavenqian2007-03-24 22:36
#37
2008-07-08 10:26
上面的这位啊,
你的链接地址有问题
1