日期:2014-05-18  浏览次数:20847 次

求联动的下拉菜单?

网上到处都是静态的下拉框联动的例子,但是最近要做一个父子下拉框都要从数据库中取值的例子,没有找到可参考的东西,求高手?
比如:
下拉框1:变压器型号
下拉框2:变压器容量
这两个值都是从数据库中读值,当变压器型号改变时候,变压器容量的值也要对应这个型号下的值
谢谢了!
--

------解决方案--------------------
用AJAX
------解决方案--------------------
<script language= "JavaScript " type= "text/javascript ">
<!--
selector1 = [ "fatherCityCodes ", "cityCode "];
menu1 = [
<%
List fatherCityList = (List)request.getAttribute( "fatherCityList ");
Iterator cityIte = fatherCityList.iterator();
int count = 0;
while(cityIte.hasNext()){
CityForm cityForm = (CityForm)cityIte.next();
if(count++> 0){
out.print( ", ");
}
out.print( "\ " "+cityForm.getCityName()+ "\ " ");
out.print( ", ");
out.print( "\ " "+cityForm.getCityCode()+ "\ " ");
out.print( ", ");

out.print( "[ ");
Iterator citySubIte = cityForm.getSubCityList().iterator();
while(citySubIte.hasNext()){
CityForm citySubForm = (CityForm) citySubIte.next();
out.print( "\ " "+citySubForm.getCityName()+ "\ " ");
out.print( ", ");
out.print( "\ " "+citySubForm.getCityCode()+ "\ " ");
out.print( ", ");
out.print( "null, ");
}
out.print( "] ");
}
%>
];


selector2 = [ "fatherVocationId ", "vocationId "];
menu2 =[
<%
List fatherVocationList =(List)request.getAttribute( "fatherVocationList ");
Iterator vocationIte = fatherVocationList.iterator();
count = 0;
while(vocationIte.hasNext()){
VocationForm vocationForm = (VocationForm)vocationIte.next();
if(count++> 0){
out.print( ", ");
}
out.print( "\ " "+vocationForm.getVocationName()+ "\ " ");
out.print( ", ");
out.print( "\ " "+vocationForm.getVocationCode()+ "\ " ");
out.print( ", ");

out.print( "[ ");
Iterator vocationSubIte = vocationForm.getSubVocationList().iterator();
while(vocationSubIte.hasNext()){
VocationForm vocationSubForm = (VocationForm) vocationSubIte.next();
out.print( "\ " "+vocationSubForm.getVocationName()+ "\ " ");
out.print( ", ");
out.print( "\ " "+vocationSubForm.getVocationCode()+ "\ " ");
out.print( ", ");
out.print( "null, ");
}
out.print( "] ");
}
%>
];
-->
</script>
function wizz1(level)
{
if( level == 0 )
a = menu;
else {
str = "menu1 ";
for( i=0; i <level; i++ )
str += "[ " + (document.all[selector1[i]].selectedIndex * 3 + 2) + "] ";
a = eval(str);
}
if( a == null ) return;
s = document.all[selector1[level]];
i = s.length;
while( i > 0 ) s.options[--i] = null;
while( i < Math.floor(a.length/3) ) {
s.options[i] = Option( a[i*3], a[i++*3+1] );

}
s.onchange = Function( "wizz1( " + (level+1) + ") ");
wizz1(level+1);
}
<