注意点:
1、 value值的设置
2、select的onchange事件
*{
margin:0;
padding:0;
}
#pro,#city,#county{
width: 120px;
height: 30px;
margin-left: 10px;
margin-top: 20px;
}
#city,#county{
display: none;
}
//获取元素
var pro = document.getElementById('pro');
var city = document.getElementById('city');
var county = document.getElementById('county');
var proStr = '';
for(var i in address[0]){
proStr += '';
}
pro.innerHTML = proStr;
//省发生改变时,显示相应的市
pro.onchange = function(){
city.style.display = 'inline-block';
var cityStr = '';
var index = this.value;
if(index == ''){
city.style.display = 'none';
county.style.display = 'none';
return;
}
for(var i in address[index]){
cityStr += '';
}
city.innerHTML = cityStr;
}
//市发生改变时,显示相应的县
city.onchange = function(){
county.style.display = 'inline-block';
var countyStr = '';
var index = this.value;
if(index == ''){
county.style.display = 'none';
return;
}
for(var i in address[index]){
countyStr += '';
}
county.innerHTML = countyStr;
}