无限级联下拉菜单代码
来源:
互联网
日期:2008-4-30
<script language="javascript"> //<!-- var arrArea=new Array( [0,"中国大陆","10"], [1,"湖北","1004"], [2,"鄂州市","1005"], [2,"恩施土家族苗族自治州","1006"], [3,"巴东县","1007"], [3,"恩施市","1008"], [3,"鹤峰县","1009"], [3,"建始县","1010"], [3,"来凤县","1011"], [3,"利川市","1012"], [3,"咸丰县","1013"], [3,"宣恩县","1014"], [2,"黄冈","1015"], ..... [2,"绥化","989"], [3,"安达市","990"], [3,"海伦市","991"], [3,"兰西县","992"], [3,"明水县","993"], [3,"青冈县","994"], [3,"庆安县","995"], [3,"绥化市","996"], [3,"绥棱县","997"], [3,"望奎县","998"], [3,"肇东市","999"] ); /* ******************** ******************** ******************************** */ function getRoute(dic,value,mode){ var strRoute,intDepth=-1; for(var i=dic.length-1;i>-1;i--){ if(intDepth>-1){ if(intDepth==0) return(strRoute); if(dic[i][0]<intDepth){ strRoute=i+","+strRoute; intDepth--; } }else{ if(dic[i][mode]==value){ strRoute=i.toString(); intDepth=dic[i][0]; } } } return(strRoute); } function getRoutes(dic,route,mode){ var strRoute="",depth=0; var arrRoute=route.split(","); var intDepth=arrRoute.length-1; for(var i=0;i<dic.length;i++){ if(dic[i][mode]==arrRoute[depth]){ if(strRoute)strRoute+=","+i; else strRoute=i.toString(); if(depth==intDepth)return(strRoute); else depth++; } } return(strRoute); } function drawSelect(obj,dicName){ var argv=drawSelect.arguments; var argc=drawSelect.arguments.length; var mode=(argc>2)?argv[2]:0; var name=(argc>3)?argv[3]:""; var value=(argc>4)?argv[4]:""; var tips=(argc>5)?argv[5]:""; var prop=(argc>6)?argv[6]:""; var beSel=(argc>7)?argv[7]:0;
var dic=eval(dicName),objValue="",noSel=0; switch(mode){ case 0:value=getRoute(dic,value,2);mode=5;break; case 1:value=getRoutes(dic,value,1);mode=6;break; case 2:value=getRoute(dic,value,1);mode=7;break; case 3:value=getRoutes(dic,value,2);mode=8;break; } var strRoute="",arrRoute=new Array(); if(value)arrRoute=value.split(","); var strHtml="",arrHtml=new Array(); var intDepth,strTitle,strValue,j,selDepth=0; for(var i=0;i<dic.length;i++){ intDepth=dic[i][0];strTitle=dic[i][1];strValue=dic[i][2]; if(intDepth==selDepth){ if(arrHtml[selDepth]==null){ arrHtml[selDepth]="<select onChange={drawSelect
(this.parentNode,\""+dicName+"\","+mode+",\""+name+"\",this.value,\""+tips+"\",\""+prop+"\","+beSel+")} "+prop+">"; if(tips){ if(beSel)noSel=1; if(selDepth)arrHtml[selDepth]+="<option
value=\""+strRoute+"\">"+tips+"</option>"; else arrHtml[selDepth]+="<option value=\"\">"+tips+"</option>"; if(arrRoute[selDepth]==null)arrRoute[selDepth]=-1; }else if(arrRoute[selDepth]==null)arrRoute[selDepth]=i; } if(i==arrRoute[selDepth]){ noSel=0; arrHtml[selDepth]+="<option value=\""+strRoute+i.toString()+"\"
selected>"+strTitle+"</option>"; selDepth++; strRoute+=i.toString()+","; switch(mode){ case 5:objValue=strValue;break; case 6:if(objValue)objValue+=","+strTitle;else objValue=strTitle;break; case 7:objValue=strTitle;break; case 8:if(objValue)objValue+=","+strValue;else objValue=strValue;break; } }else{ arrHtml[selDepth]+="<option value=\""+strRoute+i.toString()
+"\">"+strTitle+"</option>"; } }else if(intDepth<selDepth){ selDepth=intDepth; strRoute=""; for(j=0;j<selDepth;j++)strRoute+=arrRoute[j]+","; arrHtml[selDepth]+="<option value=\""+strRoute+i.toString()+"\">"+strTitle+"</option>"; } } for(i=0;i<arrHtml.length;i++){ strHtml+=arrHtml[i]+"</select>"; } if(noSel)objValue=""; strHtml+="<input type=\"hidden\" value=\""+objValue+"\" name=\""+name+"\" id=\""+name+"\">"; if(obj==null)document.write("<span>"+strHtml+"</span>"); else obj.innerHTML=strHtml; } /* ******************** ******************** ******************************** */ function getRoute(dic,value,mode){ var strRoute,intDepth=-1; for(var i=dic.length-1;i>-1;i--){ if(intDepth>-1){ if(intDepth==0) return(strRoute); if(dic[i][0]<intDepth){ strRoute=i+","+strRoute; intDepth--; } }else{ if(dic[i][mode]==value){ strRoute=i.toString(); intDepth=dic[i][0]; } } } return(strRoute); }
function getRoutes(dic,route,mode){ var strRoute="",depth=0; var arrRoute=route.split(","); var intDepth=arrRoute.length-1; for(var i=0;i<dic.length;i++){ if(dic[i][mode]==arrRoute[depth]){ if(strRoute)strRoute+=","+i; else strRoute=i.toString(); if(depth==intDepth)return(strRoute); else depth++; } } return(strRoute); } function drawSelect(obj,dicName){ var argv=drawSelect.arguments; var argc=drawSelect.arguments.length; var mode=(argc>2)?argv[2]:0; var name=(argc>3)?argv[3]:""; var value=(argc>4)?argv[4]:""; var tips=(argc>5)?argv[5]:""; var prop=(argc>6)?argv[6]:""; var beSel=(argc>7)?argv[7]:0;
var dic=eval(dicName),objValue="",noSel=0; switch(mode){ case 0:value=getRoute(dic,value,2);mode=5;break; case 1:value=getRoutes(dic,value,1);mode=6;break; case 2:value=getRoute(dic,value,1);mode=7;break; case 3:value=getRoutes(dic,value,2);mode=8;break; } var strRoute="",arrRoute=new Array(); if(value)arrRoute=value.split(","); var strHtml="",arrHtml=new Array(); var intDepth,strTitle,strValue,j,selDepth=0; for(var i=0;i<dic.length;i++){ intDepth=dic[i][0];strTitle=dic[i][1];strValue=dic[i][2]; if(intDepth==selDepth){ if(arrHtml[selDepth]==null){ arrHtml[selDepth]="<select onChange={drawSelect
(this.parentNode,\""+dicName+"\","+mode+",\""+name+"\",this.value,\""+tips+"\",\""+prop+"\","+beSel+")} "+prop+">"; if(tips){ if(beSel)noSel=1; if(selDepth)arrHtml[selDepth]+="<option
value=\""+strRoute+"\">"+tips+"</option>"; else arrHtml[selDepth]+="<option value=\"\">"+tips+"</option>"; if(arrRoute[selDepth]==null)arrRoute[selDepth]=-1; }else if(arrRoute[selDepth]==null)arrRoute[selDepth]=i; } if(i==arrRoute[selDepth]){ noSel=0; arrHtml[selDepth]+="<option value=\""+strRoute+i.toString()+"\"
selected>"+strTitle+"</option>"; selDepth++; strRoute+=i.toString()+","; switch(mode){ case 5:objValue=strValue;break; case 6:if(objValue)objValue+=","+strTitle;else objValue=strTitle;break; case 7:objValue=strTitle;break; case 8:if(objValue)objValue+=","+strValue;else objValue=strValue;break; } }else{ arrHtml[selDepth]+="<option value=\""+strRoute+i.toString()
+"\">"+strTitle+"</option>"; } }else if(intDepth<selDepth){ selDepth=intDepth; strRoute=""; for(j=0;j<selDepth;j++)strRoute+=arrRoute[j]+","; arrHtml[selDepth]+="<option value=\""+strRoute+i.toString()+"\">"+strTitle+"</option>"; } } for(i=0;i<arrHtml.length;i++){ strHtml+=arrHtml[i]+"</select>"; } if(noSel)objValue=""; strHtml+="<input type=\"hidden\" value=\""+objValue+"\" name=\""+name+"\" id=\""+name+"\">"; if(obj==null)document.write("<span>"+strHtml+"</span>"); else obj.innerHTML=strHtml; } /* ******************** ******************** ******************************** */ drawSelect(null,"arrArea");//仅仅绘制菜单 document.write("<hr>"); drawSelect(null,"arrArea",1,"strArea","中国大陆,湖南,长沙,长沙市"); document.write("默认中国大陆,湖南,长沙,长沙市"); //--> </script>
更多的无限级联下拉菜单代码请到论坛查看: http://BBS.TC711.COM
【 双击滚屏 】 【 评论 】 【 收藏 】 【 打印 】 【 关闭 】
来源:
互联网
日期:2008-4-30
|
|
|