js的省市二级联动问题,高手来啊 20
prov="北京,天津,河北,山西,内蒙古,辽宁,吉林,黑龙江,上海,江苏,浙江,安徽,福建,江西,山东,河南,湖北,湖南,广东,广西,海南,重庆,四川,贵州,云南,西藏...
prov = "北京,天津,河北,山西,内蒙古,辽宁,吉林,黑龙江,上海,江苏,浙江,安徽,福建,江西,山东,河南,湖北,湖南,广东,广西,海南,重庆,四川,贵州,云南,西藏,陕西,甘肃,青海,宁夏,新疆,台湾,香港,澳门,国外"
code = "11,12,13,14,15,21,22,23,31,32,33,34,35,36,37,41,42,43,44,45,46,50,51,52,53,54,61,62,63,64,65,71,81,82,83"
prov0 = ""
code0 = ""
prov11 = "东城区,西城区,崇文区,宣武区,朝阳区,丰台区,石景山区,海淀区,门头沟区,房山区,通州区,顺义区,昌平区,大兴区,怀柔区,平谷区,密云县,延庆县"
code11 = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18"
prov12 = "和平区,河东区,河西区,南开区,河北区,红桥区,塘沽区,汉沽区,大港区,东丽区,西青区,津南区,北辰区,武清区,宝坻区,宁河县,静海县,蓟县"
code12 = "19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36"
——————————————————————————————
上面是省市代码,很多,我只COPY了一点
网页里这样调用
————
所在地区:</DIV><LABEL class=reg_area><SELECT
onblur=cityCheck(); id=province1 onfocus=setCityTip(); onchange=Bulid_City(province1,0);
name=province1><OPTION value=0>请选择</OPTION>
<OPTION value=11>北京</OPTION> <OPTION
value=12>天津</OPTION> <OPTION value=13>河北</OPTION>
<OPTION value=14>山西</OPTION></SELECT> </LABEL><LABEL class=reg_area><SELECT
onblur=cityCheck(); id=city onchange=Bulid_City(); name=city> <OPTION
selected value=0>请选择</OPTION></SELECT>
——————————
现在怎么才能根据省的选择,显示城市呢??就是onchange=Bulid_City()这个涵数该怎么写啊,求高人帮我
——————————
我找到一段
function Bulid_City(provinceid,type)
{
var cityid = "";
if(provinceid == "province" || typeof(provinceid)=="undefined"){
cityid = "city";
}else if(provinceid == "nprovince"){
cityid = "ncity";
}else if(provinceid == "h_province"){
cityid = "h_city";
}else if(provinceid == "homeprovince"){
cityid = "homecity";
}
else if(provinceid == "tprovince"){
cityid = "tcity";
}
var province;
if(typeof(provinceid)=="undefined")
province = $("province");
else
province = $(provinceid);
var city = $(cityid);
var provcode = province.options[province.selectedIndex].value;
city.options[0].value = "0";
if(type == 'no'){
city.options[0].text = "--不限--";
}else{
city.options[0].text = "请选择";
}
if (provcode == 0)
{
city.options.length = 1;
}else{
var citylist = eval("prov" + provcode + ".split(',')");
var codelist = eval("code" + provcode + ".split(',')");
city.options.length = citylist.length + 1;
for(var i=1; i<citylist.length+1; i++)
{
city.options[i].value = codelist[i-1];
city.options[i].text = citylist[i-1];
}
}
city.selectedIndex=0;
return false;
}
但放进去还是不显示,请帮我改改这个涵数吧 展开
code = "11,12,13,14,15,21,22,23,31,32,33,34,35,36,37,41,42,43,44,45,46,50,51,52,53,54,61,62,63,64,65,71,81,82,83"
prov0 = ""
code0 = ""
prov11 = "东城区,西城区,崇文区,宣武区,朝阳区,丰台区,石景山区,海淀区,门头沟区,房山区,通州区,顺义区,昌平区,大兴区,怀柔区,平谷区,密云县,延庆县"
code11 = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18"
prov12 = "和平区,河东区,河西区,南开区,河北区,红桥区,塘沽区,汉沽区,大港区,东丽区,西青区,津南区,北辰区,武清区,宝坻区,宁河县,静海县,蓟县"
code12 = "19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36"
——————————————————————————————
上面是省市代码,很多,我只COPY了一点
网页里这样调用
————
所在地区:</DIV><LABEL class=reg_area><SELECT
onblur=cityCheck(); id=province1 onfocus=setCityTip(); onchange=Bulid_City(province1,0);
name=province1><OPTION value=0>请选择</OPTION>
<OPTION value=11>北京</OPTION> <OPTION
value=12>天津</OPTION> <OPTION value=13>河北</OPTION>
<OPTION value=14>山西</OPTION></SELECT> </LABEL><LABEL class=reg_area><SELECT
onblur=cityCheck(); id=city onchange=Bulid_City(); name=city> <OPTION
selected value=0>请选择</OPTION></SELECT>
——————————
现在怎么才能根据省的选择,显示城市呢??就是onchange=Bulid_City()这个涵数该怎么写啊,求高人帮我
——————————
我找到一段
function Bulid_City(provinceid,type)
{
var cityid = "";
if(provinceid == "province" || typeof(provinceid)=="undefined"){
cityid = "city";
}else if(provinceid == "nprovince"){
cityid = "ncity";
}else if(provinceid == "h_province"){
cityid = "h_city";
}else if(provinceid == "homeprovince"){
cityid = "homecity";
}
else if(provinceid == "tprovince"){
cityid = "tcity";
}
var province;
if(typeof(provinceid)=="undefined")
province = $("province");
else
province = $(provinceid);
var city = $(cityid);
var provcode = province.options[province.selectedIndex].value;
city.options[0].value = "0";
if(type == 'no'){
city.options[0].text = "--不限--";
}else{
city.options[0].text = "请选择";
}
if (provcode == 0)
{
city.options.length = 1;
}else{
var citylist = eval("prov" + provcode + ".split(',')");
var codelist = eval("code" + provcode + ".split(',')");
city.options.length = citylist.length + 1;
for(var i=1; i<citylist.length+1; i++)
{
city.options[i].value = codelist[i-1];
city.options[i].text = citylist[i-1];
}
}
city.selectedIndex=0;
return false;
}
但放进去还是不显示,请帮我改改这个涵数吧 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询