layui 弹出框保存

	需求是要在父页面弹出子页面,子页面是个表单。
	我写这个的时候过程很曲折,一直报错说是找不到formSubmit
父js,自己想办法触发openAddPage

var iframeWin;
function openAddPage(title, url) {
	var that = this;
	layer.open({
		type: 2,
		title: title,
		area: ['100%', '100%'],
		shade: 0.4,
		maxmin: true,
		content: url,
		btn: ['取消', '保存'],
		yes: function (index, layero) {
			layer.close(index);
		},
		btn2: function (index, layero) {
			iframeWin.formSubmit();
			return false;
		},
		end: function () {
		},
		success: function (layero, index) {
			iframeWin = window[layero.find('iframe')[0]['name']]; // 得到iframe页的窗口对象,执行iframe页的方法:iframeWin.method();
		}
	});
}
子页面html


<body style="padding: 10px 50px;">
<form class="layui-form" id="latentForm" name="latentForm" action="xxxxxxxxxxxxxx" method="post">

    <div class="layui-col-xs3">
        <div class="layui-form-item">
            <label class="layui-form-label" style="color: #c2c2c2; ">
                引入单号:
            </label>
            <div class="layui-input-block">
                <input type="text" name="project_code" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="color: #c2c2c2; ">
                币别:
            </label>
            <div class="layui-input-block">
                <input type="text" name="project_name" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>

    // 保存
    <button type="submit" lay-submit lay-filter="latentFormgo" style="display: none;" name="dosubmit" id="dosubmit"></button>
</form>
</body>


子页面js,这两个是分开两文件


layui.config({
    base: "../dist/",
    version: 20230804
}).extend({
    formSelects: 'modules/formSelects-v4',
}).use(['layer', 'table', 'form', 'laytpl', 'table', "formSelects", 'laydate'], function () {
    let $ = layui.$;
    let layer = layui.layer;
    let laytpl = layui.laytpl;
    let form = layui.form;
    let table = layui.table;
    let formSelects = layui.formSelects;
    let laydate = layui.laydate;


    form.on('submit(latentFormgo)', function(data){
        console.log(12121212)
        var loading = layer.msg('正在保存', {icon: 16, shade: 0.3, time:0});
		
        // TODO
    });

});

//触发submit按钮点击
function formSubmit() {
    document.latentForm.dosubmit.click();
}


你可能感兴趣的:(layui,javascript,前端)