layui switch 确定之后才变更状态
let x = data.elem.checked;
data.elem.checked = !x;
form.render();
完整代码
form.on('switch(is_enable)', function (data) {
let _this = $(this);
let id = _this.parent().parent().data('id');
let x = data.elem.checked;
data.elem.checked = !x;
form.render();
//询问框
layer.confirm('确定启用吗?启用后将不可编辑。', {
btn: ['确定', '取消'] //按钮
}, function () {
$.ajax({
type: 'POST',
url: 'setEnable',
data: {'id': id},
dataType: 'json',
success: function (res) {
if (res.errno == 0) {
window.location.reload();
} else {
layer.msg(res.errdesc);
}
},
error: function () {
layer.msg("网络错误");
}
});
}, function () {
});
});