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 () {
    });
});


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM