++) {
72 //------c.city[index].city[index2].area[i]是JSON文件下最外层city数组,的下标值为index的对象里,为city的数组,的下标为index2的对象里,为area数组,的下标为i,所对应的值----------
73 option_3 += '<option>' + c.city[index].city[index2].area[i] + '</option>';
74 }
75 sel_3.innerHTML = option_3;
76 }
77 //-----------------------------------------------------------------------------------------------
78 }
79 }
80 }
81 //--------第二个select(省级)触发onchange事件部分----------
82 function sel_two() {
83 //-------sel_1.selectedIndex为第一个select(省级)当前选中内容所在的索引值-----------
84 //-------sel_2.selectedIndex为第二个select(城市)当前选中内容所在的索引值-----------
85 //-------sel_1.selectedIndex - 1;减去 1 是因为第一个select(省级)的第一个内容为"请选择所在的省市"---------
86 //-------导致所有对应的省市内容的索引值均变大 1 --------------------
87 var index = sel_1.selectedIndex - 1;
88 var index2 = sel_2.selectedIndex;
89 oAjax.open('GET', 'json/city.json', true);
90 oAjax.send();
91 oAjax.onreadystatechange = function () {
92 if (oAjax.readyState == 4 && oAjax.status == 200) {
93 var c = JSON.parse(oAjax.responseText);
94 //------判断 当第二个select(城市)当前的内容 与 JSON文件下最外层city数组,下标是index的对象里,为city的数组,的下标为index2的对象里,为name属性所对应的值 相等时----------
95 if (sel_2.value == c.city[index].city[index2].name) {
96 //-----option_3是生成select(县区)内的HTML内容--------
97 var option_3 = '';
98 for (var i = 0; i < c.city[index].city[index2].area.length; i++) {
99 //------c.city[index].city[index2].area[i]是JSON文件下最外层city数组,的下标值为index的对象里,为city的数组,的下标为index2的对象里,为area数组,的下标为i,所对应的值----------
100 option_3 += '<option>' + c.city[index].city[index2].area[i] + '</option>';
101 }
102 sel_3.innerHTML = option_3;
103 }
104 }
105 }
106 }
107 </script>
108
109 </body>
|