layui2.5 开关在confirm确认了之后在关/开

<!--默认选中-->
<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');
                });
            });
})            

 

posted @ 2019-10-09 11:31  早上六点半遇见五月天  Views(1018)  Comments(0Edit  收藏  举报