<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<!-- 下拉选择框 -->
<select name="province" id="province">
</select>
<select name="city" id="city">
<!-- <option value=""></option> -->
</select>
<select name="area" id="area"></select>
<script>
var data = {
'86': {
"110000": "北京市",
"120000": "天津市",
"130000": "河北省",
"140000": "山西省",
"150000": "内蒙古自治区",
"210000": "辽宁省",
"220000": "吉林省",
"230000": "黑龙江省",
"310000": "上海市",
"320000": "江苏省",
"330000": "浙江省",
"340000": "安徽省",
"350000": "福建省",
"360000": "江西省",
"370000": "山东省",
"410000": "河南省",
"420000": "湖北省",
"430000": "湖南省",
"440000": "广东省",
"450000": "广西壮族自治区",
"460000": "海南省",
"500000": "重庆市",
"510000": "四川省",
"520000": "贵州省",
"530000": "云南省",
"540000": "西藏自治区",
"610000": "陕西省",
"620000": "甘肃省",
"630000": "青海省",
"640000": "宁夏回族自治区",
"650000": "新疆维吾尔自治区",
"710000": "台湾省",
"810000": "香港特别行政区",
"820000": "澳门特别行政区"
},
"110000": {
"110100": "市辖区"
},
"110100": {
"110101": "东城区",
"110102": "西城区",
"110105": "朝阳区",
"110106": "丰台区",
"110107": "石景山区",
"110108": "海淀区",
"110109": "门头沟区",
"110111": "房山区",
"110112": "通州区",
"110113": "顺义区",
"110114": "昌平区",
"110115": "大兴区",
"110116": "怀柔区",
"110117": "平谷区",
"110118": "密云区",
"110119": "延庆区"
},
"120000": {
"120100": "市辖区"
},
"120100": {
"120101": "和平区",
"120102": "河东区",
"120103": "河西区",
"120104": "南开区",
"120105": "河北区",
"120106": "红桥区",
"120110": "东丽区",
"120111": "西青区",
"120112": "津南区",
"120113": "北辰区",
"120114": "武清区",
"120115": "宝坻区",
"120116": "滨海新区",
"120117": "宁河区",
"120118": "静海区",
"120119": "蓟州区"
},
"130000": {
"130100": "石家庄市",
"130200": "唐山市",
"130300": "秦皇岛市",
"130400": "邯郸市",
"130500": "邢台市",
"130600": "保定市",
"130700": "张家口市",
"130800": "承德市",
"130900": "沧州市",
"131000": "廊坊市",
"131100": "衡水市"
},
"130100": {
"130101": "市辖区",
"130102": "长安区",
"130104": "桥西区",
"130105": "新华区",
"130107": "井陉矿区",
"130108": "裕华区",
"130109": "藁城区",
"130110": "鹿泉区",
"130111": "栾城区",
"130121": "井陉县",
"130123": "正定县",
"130125": "行唐县",
"130126": "灵寿县",
"130127": "高邑县",
"130128": "深泽县",
"130129": "赞皇县",
"130130": "无极县",
"130131": "平山县",
"130132": "元氏县",
"130133": "赵县",
"130171": "石家庄高新技术产业开发区",
"130172": "石家庄循环化工园区",
"130181": "辛集市",
"130183": "晋州市",
"130184": "新乐市"
},
"130200": {
"130201": "市辖区",
"130202": "路南区",
"130203": "路北区",
"130204": "古冶区",
"130205": "开平区",
"130207": "丰南区",
"130208": "丰润区",
"130209": "曹妃甸区",
"130224": "滦南县",
"130225": "乐亭县",
"130227": "迁西县",
"130229": "玉田县",
"130271": "河北唐山芦台经济开发区",
"130272": "唐山市汉沽管理区",
"130273": "唐山高新技术产业开发区",
"130274": "河北唐山海港经济开发区",
"130281": "遵化市",
"130283": "迁安市",
"130284": "滦州市"
},
};
function init(elementId, data) {
let inner = '';
for (let city in data) {
inner += '<option value="' + city + '">' + data[city] + '</option>';
}
document.getElementById(elementId).innerHTML = inner;
}
//初始化数据
init('province', data['86']);
init('city',data['110000']);
init('area',data['110100'])
let province = document.getElementById('province');
province.addEventListener('change', function () {
// alert(this.value);
init('city', data[this.value]); //发生change事件,完成后有各个城市的选择
init('area',data[document.getElementById('city').value]); //改变县的区域,修改初始
})
let city = document.getElementById('city');
city.addEventListener('change', function () {
// alert(this.value);
init('area', data[this.value]);
})
</script>
</body>
</html>