abstract: layui.use('form', function () { $ = layui.jquery; var form = layui.form; form.on('select(province)
layui.use('form', function () {
$ = layui.jquery;
var form = layui.form;
form.on('select(province)', function () {
// console.log($('#province').val());
var data = {
province: $('#province').val()
};
$.post('/index.php/index/index/change', data, function (data) {
console.log(data);
// var script = data.forEach(function () {
//
// });
var html = "<option value=''></option>";
$('#city').html(html);
$('#town').html(html);
if (data.length != 0) {
$('#city').removeAttr('disabled');
data.forEach(function (v) {
// console.log(v);
var html = $('#city').html();
var html = html + "<option value='" + v.id + "'>" + v.name + "</option>"
$('#city').html(html);
});
}
if (data.length == 0) {
$('#city').attr('disabled', 'disabled');
$('#town').attr('disabled', 'disabled');
}
form.render('select');
});
});
form.on('select(city)', function () {
// console.log($('#province').val());
var data = {
province: $('#city').val()
};
$.post('/index.php/index/index/change', data, function (data) {
// console.log(data);
if (data.length != 0) {
$('#town').removeAttr('disabled');
var html = "<option value=''></option>";
$('#town').html(html);
data.forEach(function (v) {
// console.log(v);
var html = $('#town').html();
var html = html + "<option value='" + v.id + "'>" + v.name + "</option>";
$('#town').html(html);
});
}
if (data.length == 0) {
var html = "<option value=''></option>";
$('#town').html(html);
$('#town').attr('disabled', 'disabled');
}
form.render('select');
});
});
form.on('select(province_home)', function () {
var data = {
province: $('#province_home').val()
};
$.post('/index.php/index/index/change', data, function (data) {
var html = "<option value=''></option>";
$('#city_home').html(html);
$('#town_home').html(html);
if (data.length != 0) {
$('#city_home').removeAttr('disabled');
data.forEach(function (v) {
// console.log(v);
var html = $('#city_home').html();
var html = html + "<option value='" + v.id + "'>" + v.name + "</option>"
$('#city_home').html(html);
});
}
if (data.length == 0) {
$('#city_home').attr('disabled', 'disabled');
$('#town_home').attr('disabled', 'disabled');
}
form.render('select');
});
});
form.on('select(city_home)', function () {
// console.log($('#province').val());
var data = {
province: $('#city_home').val()
};
$.post('/index.php/index/index/change', data, function (data) {
// console.log(data);
if (data.length != 0) {
$('#town_home').removeAttr('disabled');
var html = "<option value=''></option>";
$('#town_home').html(html);
data.forEach(function (v) {
// console.log(v);
var html = $('#town_home').html();
var html = html + "<option value='" + v.id + "'>" + v.name + "</option>";
$('#town_home').html(html);
});
}
if (data.length == 0) {
var html = "<option value=''></option>";
$('#town_home').html(html);
$('#town_home').attr('disabled', 'disabled');
}
form.render('select');
});
});
});//layui的三级联动
Correcting teacher:天蓬老师Correction time:2019-05-27 13:13:56
Teacher's summary:三联联动的关键在于事件与内容的异步加载, 这是核心内容