android省市区 简书,三级联动(省市区)

js数据:

b41d8b39f39d

代码

html>

console.log(arr);

var province = document.querySelector('#province')

var city = document.querySelector('#city')

var area = document.querySelector('#area')

function init() {

arr.forEach(function (item) {

province.innerHTML += `${item.name}`

})

arr[0].city.forEach(function (item) {

city.innerHTML += `${item.name}`

})

arr[0].city[0].districtAndCounty.forEach(function (item) {

area.innerHTML += `${item}`

})

}

init()

var currentProvince=null

province.onchange = function () {

// 清空 市

city.length = 0

area.length = 0

console.log(this.value);

var _this = this

currentProvince = arr.filter(function (item) {//函数 里面的函数  里面的this 一般不指向前者

return item.name == _this.value

})

console.log(currentProvince);

// 渲染市和区

currentProvince[0].city.forEach(function (item) {

city.innerHTML += `${item.name}`

})

currentProvince[0].city[0].districtAndCounty.forEach(function (item) {

area.innerHTML += `${item}`

})

}

city.onchange = function () {

// 每次改变市 清空区

area.length = 0

var _this = this

var currentCity = currentProvince[0].city.filter(function (item) {

return item.name == _this.value

})

console.log(currentCity);

currentCity[0].districtAndCounty.forEach(function (item) {

area.innerHTML += `${item}`

})

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值