设为首页 加入收藏

TOP

2.省市区,三级联动(注释详解)。(二)
2019-09-17 18:27:05 】 浏览:33
Tags:省市区 三级 联动 注释 详解
++) { 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>

 

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Vuex的简单认识 下一篇Vue.js 源码分析(十二) 基础篇 组..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目