<input type="checkbox" lay-filter="common_change_status" name="switch" lay-text="显示|不显示" data-type="is_show" data-q="{$vo.is_show}" lay-skin="switch" <?php if($vo['is_show'] == 1) { echo 'checked'; } ?> >
layui.use(['form'], function () { // 自动化加载
var form = layui.form;
form.on('switch(common_change_status)', function(data){
var _this = $(this);
var id = $(this).parent().parent().data('id');
var table = $(this).parent().parent().data('table');
var type = $(this).data('type');
var q = $(this).data('q');
var sold;
if(q == '1'){
sold = 0;
}else{
sold = 1;
}
$.ajax({
type :'POST',
url :'/admin.php/Common/set',
data :{'id':id,'type':type,'set_val':sold,'table':table},
dataType:'json',
success:function(data){
if(data.errno == 0){
_this.data('q',sold);
} else {
layer.msg(data.errdesc);
}
},
error:function(){
layer.msg("网络错误");
}
});
});
});
原文:https://www.cnblogs.com/jiqing9006/p/11180283.html