![用JSP+JavaScript打造二级级联下拉菜单](https://1200zi.500zi.com/uploadfile/img/3/386/4267bc45d3f4978db337b5729755dfd7.jpg)
今天给大家分享的是由小编精心为您推荐的用JSP+JavaScript打造二级级联下拉菜单,喜欢的朋友可以分享一下,也算是给小编一份支持,大家都不容易啊!
JSP+JavaScript打造二级级联下拉菜单:
class(一级栏目信息):classId(自动编号),className(栏目名称), Nclass(二级栏目信息), NclassId(自动编号),NclassName(栏目名称),parentId(一级栏目id,与class表中的classId关联)
%@ page contentType=text/html; charset=GB2312 language=java errorPage=../error.jsp % %@ include file=../% %@ include file=../% %@ taglib uri= divfix=sql % %(); % HTMLHEAD META http-equiv=Content-Type content=text/html; charset=gb2312 TITLE级联菜单/TITLE LINK rel=stylesheet type=text/css href=style.css /HEAD !--从数据库中得到二级栏目信息-- %String sql=select * from Nclass order by NclassId asc; ResultSet rs=(); % !--将二级栏目信息保存到数组subcat中-- script type=text/javascript var onecount; onecount=0; subcat = new Array(); % int count = 0; while(()){ % subcat[%=count%] = new Array(%=()%,%()%,%()%); % count++; } (); % onecount=%=count%; !--决定select显示的函数-- function changelocation(locationid) { = 0; var locationid=locationid; var i; for (i=0;i onecount; i++) { if (subcat[i][2] == locationid) { document.myform.NclassId.options[] = new Option(subcat[i][0], subcat[i][1]); } } }/script FORM method=POST name=myform action=? TABLETR TD一级分类/TD TD SELECT name=classId onChange=changelocation() size=1 OPTION selected value==请选一级分类==/OPTION var=query dataSource=$ SELECT* FROM class/ c:forEach var=row items=$ option value=$$/option /c:forEach /select /TD TD选择二级分类/TD TD SELECT name=NclassId OPTION selected value==请选二级分类==/OPTION /SELECT /TD /TR /TABLE /FORM /BODY /HTML%@ page contentType=text/html; charset=GB2312 language=java errorPage=../error.jsp % %@ include file=../% %@ include file=../% %@ taglib uri= divfix=sql % %(); % HTMLHEAD META http-equiv=Content-Type content=text/html; charset=gb2312 TITLE级联菜单/TITLE LINK rel=stylesheet type=text/css href=style.css /HEAD !--从数据库中得到二级栏目信息-- %String sql=select * from Nclass order by NclassId asc; ResultSet rs=(); % !--将二级栏目信息保存到数组subcat中-- script type=text/javascript var onecount; onecount=0; subcat = new Array(); % int count = 0; while(()){ % subcat[%=count%] = new Array(%=()%,%()%,%()%); % count++; } (); % onecount=%=count%; !--决定select显示的函数-- function changelocation(locationid) { = 0; var locationid=locationid; var i; for (i=0;i onecount; i++) { if (subcat[i][2] == locationid) { document.myform.NclassId.options[] = new Option(subcat[i][0], subcat[i][1]); } } }/script FORM method=POST name=myform action=? TABLETR TD一级分类/TD TD SELECT name=classId onChange=changelocation() size=1 OPTION selected value==请选一级分类==/OPTION var=query dataSource=$ SELECT * FROM class/ c:forEach var=row items=$ option value=$$/option /c:forEach /select /TD TD选择二级分类/TD TD SELECT name=NclassId OPTION selected value==请选二级分类==/OPTION /SELECT /TD /TR /TABLE /FORM /BODY /HTML