<!--默认选中-->
<div class="layui-form-item layui-form">
     <div class="layui-input-block">
         <input lay-filter="used" type="checkbox" value="1" name="status" lay-skin="switch" lay-text="有效|禁用" checked>
    </div>
</div>    
//js
layui.use(['laydate', 'layer', 'element', 'form','laypage'], function() {
    form = layui.form,
     form.on('switch(used)', function(data){
                var status = data.elem.checked;
                if(!status){
                    var title = '确定禁用吗?';
                }else{
                    var title = '重新启用吗?';
                }
                layer.confirm(title,{icon:3,title:'提示'},function (index) {
                    layer.close(index);
                },function (index) {
                    //如果取消了的话,恢复原来的状态
                    data.elem.checked = !data.elem.checked;//反转
                    form.render('checkbox');
                });
            });
})            
02-01 03:11