日期:2014-05-18  浏览次数:20709 次

[求助]关于省份,城市下拉框连动的问题
<form name="dataForm" id="dataForm" action="" method="POST" target="dataFrame" style="margin: 0">
<div class="InnerDiv" style="width: 780px;">
  <table align=right border=0 style="height:150; width:100%">  
  <tr>
  <td nowrap align=right>所在省份:</td>
  <td><select name=province style="width:100px" ><base:optionsFromCode codeId="provinceName"/></select></td>
  <td nowrap align=right>所在城市:</td>
  <td><input name="city" style="width:100px"></td>
  </tr>  
  </table>
</div>
</form>

var areaList={ 
"100":[["选择城区"],["东城区"],["西城区"],["崇文区"],["宣武区"],["朝阳区"],["丰台区" ],["石景山区" ],["海淀区" ],["门头沟区" ],["房山区" ],["通州区" ],["顺义区" ],["延庆县" ],["昌平县" ],["怀柔县" ],["密云县" ],["平谷县" ],["大兴县" ]], 
"200":[["选择城区"],["和平区" ],["河东区" ],["河西区" ],["南开区" ],["河北区" ],["红桥区" ],["塘沽区" ],["大港区" ],["汉沽区" ],["东丽区" ],["西青区" ],["津南区" ],["北辰区" ],["蓟县","22"],["宝坻县" ],["武清县" ],["宁河县" ],["静海县" ]], 
"300":[["选择城区"],["南市区" ],["卢湾区" ],["徐汇区" ],["长宁区" ],["静安区" ],["普陀区" ],["闸北区" ],["虹口区" ],["杨浦区" ],["闵行区" ],["宝山区" ],["嘉定区" ],["浦东新区" ],["金山区" ],["松江区" ],["崇明县" ],["青浦县" ],["南汇县" ],["奉贤县" ],["黄浦区" ]]
  }; 
province在数据库存的有值,100代表北京,200代表天津,300代表上海,city也是数值存入数据库,如东城区为101,西城区为102,和平区为201等等
要在javascript里定义事件函数.怎么才能让省份和城市产生连动,选择省份就会有相应的城市对应在里面,求高手解答下

------解决方案--------------------
我有个例子,把我的数据改下就可以了

<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",["北京市","天津市","河北省","山西省","内蒙古","辽宁省","吉林省","黑龙江省","上海市"," 江苏省","浙江省","安徽省","福建省","江西省","山东省","河南省","湖北省","湖南省","广东省","广西自治区","海南省","重庆市","四川省","贵州省","云南省","西藏自治区","陕西省","甘肃省","青海省","宁夏回族自治区&qu