layui switch 确定之后才变更状态

Posted jiqing9006

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 () 
    );
);

以上是关于layui switch 确定之后才变更状态的主要内容,如果未能解决你的问题,请参考以下文章