日期:2014-05-20  浏览次数:20736 次

求一个2级联动菜单的脚本
jsp页面的2级联动菜单,内容是从后台数据库里查出来的。
想要用脚本来实现菜单的联动,希望大家能给个简单实用的脚本外加说明!!!
谢谢

------解决方案--------------------
<script type= "text/javascript " language= "javascript ">
var subindusid=new Array( " "
<logic:present name= "subindus "> //subindus是个list的第二级数据
<logic:iterate id= "sindus " name= "subindus ">
, " <bean:write name= "sindus " property= "industryId "/> " // id
</logic:iterate>
</logic:present>
);
var subindusna=new Array( " "
<logic:present name= "subindus ">
<logic:iterate id= "sindus " name= "subindus ">
, " <bean:write name= "sindus " property= "industryName "/> " // name
</logic:iterate>
</logic:present>
);
function onsel(){
var mainid= " "+myform.mainindustry.value;
var psel=myform.subindustry.options;
for(i=psel.length-1;i> 0;i--){
myform.subindustry.remove(i);
}
if(mainid== '0 ')
return;
for(j=1;j <subindusid.length;j++){
var tl=subindusid[j].length-2;
var tst=subindusid[j].substring(0,tl);
if(tst==mainid){
opt=document.createElement ( "OPTION ");
opt.value=subindusid[j];
opt.text=subindusna[j];
myform.subindustry.add(opt);

}
}
}
</script>


<tr>
<td> 主行业: </td>
<td>
<select name= "mainindustry " onchange= "onsel(); ">
<option value= "0 " selected> <bean:message key= "mainindustry.default "/> </option>
<logic:present name= "allmainindus ">
<logic:iterate id= "indus " name= "allmainindus ">
<option value= " <bean:write name= "indus " property= "industryId "/> "> <bean:write name= "indus " property= "industryName "/> </option>
</logic:iterate>
</logic:present>
</select>
</td>
</tr>
<tr>
<td> 二级行业 </td>
<td>
<select name= "subindustry ">
<option value= "0 " selected> <bean:message key= "subindustry.default "/> </option>
</select>
</td>
</tr>