问题描述
我从网上找了一段javascript的省市级联代码,Ajax的我不会,新写了一个页面,把代码复制到页面上,没有问题,但是,放到我项目里的时候,结果写2个才能显示出来一个,写一个话就获取不到省市的值,有高手可以解决一下吗?谢了,本人实在笨,求高手解决了给我。js的代码:functionFillProvinces(selProvince){selProvince.options[0]=newOption("请选择","000000");for(i=0;i<Provinces.length;i++){selProvince.options[i+1]=newOption(Provinces[i][1],Provinces[i][0]);}selProvince.options[0].selected=true;selProvince.length=i+1;}functionFillCitys(selCity,ProvinceCode){//iftheprovinceisadirect-managedcity,likeBeijing,shanghai,tianjin,chongqin,hongkong,macro//neednot"请选择选项"if(ProvinceCode=="110000"||ProvinceCode=="120000"||ProvinceCode=="310000"||ProvinceCode=="810000"||ProvinceCode=="820000"||ProvinceCode=="500000")count=0;else{selCity.options[0]=newOption("请选择",ProvinceCode);count=1;}for(i=0;i<Citys.length;i++){if(Citys[i][0].toString().substring(0,2)==ProvinceCode.substring(0,2)){selCity.options[count]=newOption(Citys[i][1],Citys[i][0]);count=count+1;}}selCity.options[0].selected=true;selCity.length=count;}functionProvince_onchange(){FillCitys(g_selCity,g_selProvince.value);}functionInitCitySelect(selProvince,selCity){//alert("begin");g_selProvince=selProvince;g_selCity=selCity;selProvince.onchange=Function("Province_onchange();");FillProvinces(selProvince);Province_onchange();}functionInitCitySelect2(selProvince,selCity,CityCode){InitCitySelect(selProvince,selCity)for(i=0;i<selProvince.length;i++){if(selProvince.options[i].value.substring(0,2)==CityCode.substring(0,2)){selProvince.options[i].selected=true;}}Province_onchange();for(i=0;i<selCity.length;i++){if(selCity.options[i].value==CityCode){selCity.options[i].selected=true;}}}//--></script>页面的代码:<tr><tdalign="right"class="ftit">所在地区:</td><tdalign="left"><tdcolspan="2"align="center"><formname="profile"method="post"><selectid="province"size="1"name="memberTab.province"><optionselected="selected"></option></select><selectid="city"size="1"name="memberTab.city"><optionselected="selected"></option></select><scriptlanguage="javascript">InitCitySelect(document.profile.province,document.profile.city);</script></form><formname="profile"method="post"><selectid="province"size="1"name="memberTab.province"><optionselected="selected"></option></select><selectid="city"size="1"name="memberTab.city"><optionselected="selected"></option></select><scriptlanguage="javascript">InitCitySelect(document.profile.province,document.profile.city);</script></form></td></tr>页面显示的时候如果不写2个form,就无法获取到省市的值,写了2个以后,第二个才能获取出来值,第一个form是空的,不知道怎么回事?Js代码太长了,我是把所有值都放在js里的