1.
//弹框中的表单 <form class="add" lay-filter="addform" id="addform" style="display: none;"> <div class="layui-form-item"> <label class="layui-form-label">用户名</label> <div class="layui-input-block"> <input type="text" name="username" placeholder="请输入" autocomplete="off" class="layui-input" lay-filter="username"> </div> </div> <div class="layui-form-item"> <label class="layui-form-label">复选框</label> <div class="layui-input-block"> <input type="checkbox" name="like[write]" value="write" title="写作" > <input type="checkbox" name="like[read]" value="read" title="阅读" > </div> </div> </form>
2.
layui.use('layer', function(){ var layer = layui.layer; layer.open({ title: ['title', 'text-align:center; background:#fff'], type: 1, area: ['500px', '300px'], content: $('#addform'), //这里content是一个普通的String // offset: 'auto', //弹框位置 btn: ['no', 'yes'] ,btnAlign: 'c' ,btn1: function(index, layero){ alert('no')
layer.closeAll(type) - 关闭所有层 } ,btn2: function(index, layero){ alert('yes') //return false 开启该代码可禁止点击该按钮关闭 } ,cancel: function(){ //右上角关闭回调 //return false 开启该代码可禁止点击该按钮关闭 } ,success: function(layero, index){ //弹出成功的回调 console.log('弹出了'+layero, index); } }); });