日期:2014-05-16  浏览次数:20369 次

js怎么实现三级关联
myAddressArray=new   Array();
myAddressArray[0]=new   Array( '0 ', '中国 ', '-1 ');
myAddressArray[1]=new   Array( '1 ', '安徽 ', '0 ');
myAddressArray[2]=new   Array( '4 ', '福建 ', '0 ');
myAddressArray[3]=new   Array( '5 ', '甘肃 ', '0 ');
myAddressArray[4]=new   Array( '34 ', '铜陵 ', '1 ');
myAddressArray[5]=new   Array( '35 ', '屯溪 ', '1 ');
myAddressArray[6]=new   Array( '36 ', '芜湖 ', '1 ');
myAddressArray[7]=new   Array( '37 ', '宣城 ', '1 ');
myAddressArray[8]=new   Array( '38 ', '合肥 ', '1 ');
myAddressArray[9]=new   Array( '39 ', '安庆 ', '1 ');
myAddressArray[10]=new   Array( '56 ', '龙岩 ', '2 ');
myAddressArray[11]=new   Array( '57 ', '南平 ', '2 ');
myAddressArray[12]=new   Array( '58 ', '宁德 ', '2 ');
myAddressArray[13]=new   Array( '59 ', '莆田 ', '2 ');
myAddressArray[14]=new   Array( '60 ', '泉州 ', '2 ');
myAddressArray[15]=new   Array( '61 ', '三明 ', '2 ');
myAddressArray[16]=new   Array( '62 ', '邵武 ', '2 ');
myAddressArray[17]=new   Array( '70 ', '兰州 ', '3 ');
myAddressArray[18]=new   Array( '71 ', '白银 ', '3 ');
myAddressArray[19]=new   Array( '72 ', '定西 ', '3 ');
myAddressArray[20]=new   Array( '73 ', '敦煌 ', '3 ');
myAddressArray[21]=new   Array( '74 ', '甘南 ', '3 ');
myAddressArray[22]=new   Array( '75 ', '金昌 ', '3 ');


这样的数据怎么实现三级关联?

------解决方案--------------------
<html>
<head>
<title> 省市县关联菜单 </title>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<style>
body,select
{
font-size:9pt;
font-family:Verdana;
}
a
{
color:red;
text-decoration:none;
}
a:hover{
text-decoration:underline;
}
</style>
<SCRIPT LANGUAGE= "JavaScript ">
<!--
function Dsy()
{
this.Items = {};
}
Dsy.prototype.add = function(id,iArray)
{
this.Items[id] = iArray;
}
Dsy.prototype.Exists = 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));};
var ss=document.getElementById(s[v]);
with(ss){
length = 0;
options[0]=new Option(opt0[v],opt0[v]);
if(v && document.getElementById(s[v-1]).selectedIndex> 0 || !v)
{
if(dsy.Exists(str)){
ar = dsy.Items[str];
for(i=0;i <ar.length;i++)options[length]=new Option(ar[i],ar[i]);
if(v)options[1].selected = true;
}
}
if(++v <s.length){change(v);}
}
}

var dsy = new Dsy();

dsy.add( "0 ",[ "安徽 ", "北京 ", "福建 ", "甘肃 ", "广东 ", "广西 ", "贵州 ", "海南 ", "河北 ", "河南 ", "黑龙江 ", "湖北 ", "