<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>下拉级联例子</title> <script type="text/javascript"> //存放着所属关系:这里文件名0和文件名2属于部门二的,fileid作为option中value属性的值 var arr = new Array(); arr[0]=new Array("文件名0","fileid","orgid2"); arr[1]=new Array("文件名1","fileid1","orgid1"); arr[2]=new Array("文件名2","fileid2","orgid2"); function selectOrg(index,orgid){ var obj=document.getElementById('sfile'); var i; obj.options.length=0; //清除原来的下拉项 for (i=0;i < arr.length; i++){ if (arr[i][2] == orgid&&arr[i][2]!=null){ // 创建新的下拉项,参数对应为("文本"、"值")如("文件名0"、"fileid") obj.options.add(new Option(arr[i][0],arr[i][1])); } } if(obj.options.length==0){ obj.options.add(new Option("请选择","0")); //未选择时 } } </script> </head> <body > <p>某部门下有某些文件:如果是用struts1标签<html:select>,用styleId属性相当于id</p> <hr/> <table> <tr> <td> <select id="fileCatalogId" value="" onchange="selectOrg(this.selectedIndex,this.options[this.selectedIndex].value)" > <option value="0">请选择</option> <option value="orgid1">部门一</option> <option value="orgid2">部门二</option> </select> </td> <td> <select id="sfile" value=""> <option value="0">请选择</option> </select> </td> </tr> </table> </body>
?