简单的二级联动代码实例
发布日期:2022-02-27 信息来源:众旺互联 点击:次
简单的二级联动代码实例,html和js实现的简单二级联动代码,多复制一层可实现三级联动代码。
<script>
cities = new Object();
cities['河北省']=new Array('石家庄', '张家口', '承德市', '秦皇岛', '唐山');
cities['山西']=new Array('太原', '大同', '朔州', '阳泉');
function set_city(province, city)
{
var pv, cv;
var i, ii;
pv=province.value;
cv=city.value;
city.length=1;
if(pv=='0') return;
if(typeof(cities[pv])=='undefined') return;
for(i=0; i<cities[pv].length; i++)
{
ii = i+1;
city.options[ii] = new Option();
city.options[ii].text = cities[pv][i];
city.options[ii].value = cities[pv][i];
}
}
</script>
<form name="form1" action="" method="get">
<select name="province" onChange="set_city(this, this.form.city);">
<option value="0">选择省</option>
<option value="河北省">河北省</option>
<option value="山西">山西</option>
</select>
<select name="city" id="citys">
<option value="0">选择城市</option>
</select>
</form>