引用的js为WEUI+ 的city.data.js
js地址:https://gitee.com/yoby/weui.git 文件地址:/js/city.data.js
layui Html:
<div class="layui-form-item">
<label class="layui-form-label" style="width: 100px;">城市
</label>
<div class="layui-input-inline">
<select lay-filter="province" id="province" name="increment_province">
</select>
</div>
<div class="layui-input-inline">
<select lay-filter="city" id="city" name="increment_city">
</select>
</div>
<div class="layui-input-inline">
<select lay-filter="area" id="area" name="increment_area">
</select>
</div>
</div>
JQ:
$(function () {
$
.getJSON("/weui/js/city.data.js", function (data
){
var str
= '';
str
+= '<option value="0">选择省份</option>';
for(var i
in data
) {
str
+= '<option value="'+data
[i
].name
+'">'+data
[i
].name
+'</option>';
};
$('#province').html(str
);
form
.render();
})
})
form
.on('select(province)', function(datas
){
var province
= datas
.value
;
$
.getJSON("/weui/js/city.data.js", function (data
){
var str
= '';
for(var i
in data
) {
if (data
[i
].name
== province
)
{
var sub
= data
[i
].sub
;
for(var k
in sub
) {
str
+= '<option value="'+sub
[k
].name
+'">'+sub
[k
].name
+'</option>';
};
}
};
$('#city').html(str
);
form
.render();
})
})
form
.on('select(city)', function(datas
){
var province
= $('#province').val();
var city
= datas
.value
;
$
.getJSON("/weui/js/city.data.js", function (data
){
var str
= '';
for(var i
in data
) {
if (data
[i
].name
== province
)
{
var sub
= data
[i
].sub
;
for(var k
in sub
) {
if (sub
[k
].name
== city
)
{
var subs
= sub
[k
].sub
;
for(var c
in subs
) {
str
+= '<option value="'+subs
[c
].name
+'">'+subs
[c
].name
+'</option>';
};
};
};
};
};
$('#area').html(str
);
form
.render();
})
})
转载请注明原文地址:https://blackberry.8miu.com/read-1180.html