layui.open监听页面提交
$("#addBtn").on('click', function () {
layer.open({
type: 2,
content: "/add.html"
area: ['750px', '400px'],
title: '添加',
scrollbar: false,
btnAlign: 'c',
btn: ['确定', '取消'],
yes: function (index, layero) {
var iframeWin = layero.find('iframe')[0];
iframeWin.contentWindow.submitHandler(index, layero);
},
cancel: function (index) {
return true;
}
});
})
add.html
<form class="layui-form layui-form-pane" id="zrrForm" action=""
<div class="layui-form-item" style="margin-top:20px">
<div style="text-align:center">
<button class="layui-btn layui-bg-blue" style="display: none" id="btnSubmit" lay-submit
lay-filter="infoContent">
<i class="layui-icon"></i>保存
</button>
</div>
</div>
</form>
function submitHandler(index, layero) {
//模拟提交进行验证
var submit = $("#btnSubmit");
submit.trigger('click');
}
form.on('submit(infoContent)', function (data) {
var index = layer.msg("加载中.....", {time: 0, shade: 0.01});
$.ajax({
url: "/add"
type: 'post',
dataType: 'json',
data: {
requestJson: JSON.stringify(data.field)
},
success: function (res) {
layer.close(index);
if (res.code == '0') {
layer.msg(res.msg, {icon: 6, time: 1000}, function () {
//关闭当前frame
var indexFrame = parent.layer.getFrameIndex(window.name);
//刷新父页面
window.parent.refreshPage();
parent.layer.close(indexFrame);
});
} else {
layer.msg(res.msg, {icon: 5});
}
}
});
return false;
});