• layui.open监听页面提交


    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">&#xe609;</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;
            });
    
    作者: JaminYe
    版权声明:本文原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
  • 相关阅读:
    Java SSL证书的安装
    zookeeper集群配置
    ERROR org.apache.zookeeper.ClientCnxn:532
    线程池c3p0和dbcp2的配置初始化实例
    SIP/2.0 403 Forbidden(Invalid domain in From: header)
    OkHttp实现文件上传进度
    Http 缓存机制
    Cookie、Session 和 Token区别
    RecyclerView-- 侧滑删除和拖动排序
    RecyclerView--添加头部和底部
  • 原文地址:https://www.cnblogs.com/JaminYe/p/13394227.html
Copyright © 2020-2023  润新知