请教高手级联的下拉框的问题
<select id="hosSelect" onchange="changeValue()">
<option value="">医院列表</option>
<c:forEach items="${hospitalList}" var="hospital">
<option value="${hospital.hosName}">${hospital.hosName}</option>
</c:forEach>
</select>
我从后台获取到了一个List<BEAN>这个bean里面包含医院的ID name和List<department>对象,然后department这个bean里面又包含id,name,List<expert>,expert这个bean包含id,name这样一个三层结构,现在页面上我想通过选择医院-》相应的科室-》相应的专家
function changeValue(){
var hoslist = "${hospitalList}";
var hos = $("#hosSelect").val();
var size = "${hospitalList.size()}";
alert(hoslist.size());
for(var i=0; i<size ;i++){
if(hoslist[i].hosName==hos){
var deplist=hoslist[i].depBean
}
}
}这个function不知道怎么写,这我写的都是问题,size识别不了 报错,请教高手改怎么写 谢谢了
[最优解释]
动态获取ID的值
[其他解释]
好像jquery里有这功能
[其他解释]
<!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>
<script type="text/javascript">
var array=[
["华北","辽宁","沈阳"],
["西南","重庆","重庆"],
["华东","安徽","合肥"],
["华北","河南","郑州"],
["华北","吉林","长春"],
["华北","河北","石家庄"],
["西南","四川","成都"],
["西南","云南","昆明"],
["西南","贵州","贵阳"]
]
function init(s1name,s2name,jb){//alert(s1name.length+s2name);
var sl2=document.getElementById(s2name);//alert(sl2.length);
if(s1name.length==0){
//document.getElementById("s1").options[0]=new Option("--请选择--",0+"");
document.getElementById("s2").options[0]=new Option("--请选择--",0+"");
document.getElementById("s3").options[0]=new Option("--请选择--",0+"");
var sa1=[];
for(var i=0;i<array.length;i++){
if(sa1.length!=0){
var a=0;
for(var o=0;o<sa1.length;o++){//alert(sa1[o]+array[i][0]);
if(sa1[o]==array[i][0]){//alert(sa1[o]+array[i][0]);alert("OK");
a=-1;break;
}
}
if(a==0){
sa1[i]=array[i][jb];
}
}else{//alert(sa1.length+"--"+array[i][0]);
sa1[i]=array[i][jb];
}
}//alert(sa1.length);var dd="--请选择--";
sl2.options[sl2.length]=new Option("--请选择--",0+"");
for(var i=0;i<sa1.length;i++){
sl2.options[sl2.length]=new Option(sa1[i],(i+1)+"");
}
}else{
var slup=document.getElementById(s1name);
sl2.innerHTML="";
var sa=[];//alert(slup.options[slup.value].innerHTML);
for(var i=0,j=0;i<array.length;i++){
if(slup.options[slup.value].innerHTML==array[i][jb-1]){
sa[j]=array[i][jb];j++;
}
}//alert(sa.length);
sl2.options[sl2.length]=new Option("--请选择--",0+"");
for(var i=0;i<sa.length;i++){
sl2.options[sl2.length]=new Option(sa[i],(i+1)+"");
}
}
}
</script>
</head>
<body onload="javascript:init('','s1',0);">
<select name="s1" id="s1" onchange="init('s1','s2',1)"></select>
<select name="s2" id="s2" onchange="init('s2','s3',2)"></select>
<select name="s3" id="s3"></select>
</body>
</html>