js三级联动

<SCRIPT LANGUAGE="JavaScript"> 
    function Dsy() 
    { 
    this.Items={};
    } 

    Dsy.prototype.add = function(id,iArray) 
    { 
    this.Items[id] = iArray; 
    } 

    Dsy.prototype.exisits = function(id) 
    { 
    if(typeof(this.Items[id]) == "undefined") 
    return false; 
    return true; 
    } 
    
    function change(v){ 
       var str="0"; 
       for(i=0;i<v;i++){
       str+=("_"+(document.getElementById(s[i]).selectedIndex-1));}; 
       //alert(str);
       var ss=document.getElementById(s[v]); 
      //var s=["s1","s2","s3"]; 
      //var opt0 = ["省份","地级市","县级市、县"]; 
       with(ss){ 
        ss.length = 0; 
        ss.options[0]=new Option(opt0[v],opt0[v]);
        
        if(v && document.getElementById(s[v-1]).selectedIndex>0 || !v) 
        {       
        if(dsy.exisits(str)){ 
        ss.ar = dsy.Items[str]; 
        for(i=0;i<ar.length;i++)
        ss.options[length]=new Option(ar[i],ar[i]); 
        if(v)
        ss.options[1].selected = true; 
        } 
        } 
        
        
       if(++v<s.length){
        change(v);
        } 
        
        } 
        } 


var dsy = new Dsy(); 

dsy.add("0",["安徽","北京","福建"]); 

dsy.add("0_0",["安庆","蚌埠","巢湖","池州"]); 
dsy.add("0_0_0",["安庆市","怀宁县","潜山县","宿松县","太湖县"]); 
dsy.add("0_0_1",["蚌埠市","固镇县","怀远县","五河县"]); 
dsy.add("0_0_2",["巢湖市","含山县","和县","庐江县","无为县"]); 
dsy.add("0_0_3",["池州市","东至县","青阳县","石台县"]); 


dsy.add("0_1",["北京"]); 
dsy.add("0_1_0",["北京市","密云县","延庆县"]); 

dsy.add("0_2",["福州","龙岩","南平"]); 
dsy.add("0_2_0",["长乐市","福清市","福州市","连江县","罗源县","闽侯县"]); 
dsy.add("0_2_1",["长汀县","连城县","龙岩市","上杭县","武平县","永定县"]); 
dsy.add("0_2_2",["光泽县","建阳市","建瓯市","南平市","浦城县"]); 
</SCRIPT> 
<SCRIPT LANGUAGE = JavaScript> 
var s=["s1","s2","s3"]; 
var opt0 = ["省份","地级市","县级市、县"]; 
function setup() 
{ 
for(i=0;i<s.length-1;i++) 
document.getElementById(s[i]).onchange=new Function("change("+(i+1)+")"); 
change(0); 
} 
</SCRIPT> 
 </head>
<body bgcolor="#E0E0E0" onload="setup()"> 
多级关联菜单: 
<form name="frm"> 
<select id="s1"></select> 
<select id="s2"></select> 
<select id="s3"></select> 
</form> 
</body> 

 

posted @ 2012-05-03 23:13  合肥房屋托管  阅读(444)  评论(0编辑  收藏  举报