//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'); }); }); })