欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-05-27 22:53:38
//js layui.use(['laydate', 'layer', 'element', 'form','laypage'], function() { form = layui.form, form.on('switch(used)', function(data){ var s... ......
<!--默认选中-->
<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');
                });
            });
})