<td class="td-status">
{if condition="$data.state eq 1"}
<span class="layui-btn layui-btn-normal layui-btn-mini">启用</span>
{else/}
<span class="layui-btn layui-btn-normal layui-btn-mini layui-btn-disabled">停用</span>
{/if}
</td>
方法
function admin_stop(obj,id){
layer.confirm('确认要修改吗?',function(index){
if($(obj).attr('title')==1){
//发异步把用户状态进行更改
$.ajax({
type:"post",
url:"{:url('User/state')}",
data:{id:id,state:0},
dataType:'json',
success:function(res){
if (res.code == 200) {
$(obj).attr('title','0')
$(obj).find('i').html('');
$(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('停用');
layer.msg('已修改!',{icon: 5,time:1000});
window.location.reload();
}
}
})
}else{
$.ajax({
type:"post",
url:"{:url('User/state')}",
data:{id:id,state:1},
dataType:'json',
success:function(res){
if (res.code == 200) {
$(obj).attr('title','1')
$(obj).find('i').html('');
$(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-mini').html('启用');
layer.msg('已修改!',{icon: 5,time:1000});
window.location.reload();
}
}
});
}
});
}
控制器
//状态
public function state(){
$data = input("post.");
unset($data['id']);
$id = input("id");
$res = Db::name('user')->where('id',$id)->update($data);
if($res){
return json(['code' => 200,'msg' => '修改成功']);
}
}