zoukankan      html  css  js  c++  java
  • layer.open+iframe页窗口=在父页面利用 layer.open的yes按钮回调函数调用iframe子页面函数

    父页面

            function edit(data) {
                layer.open({
                    type: 2,//0:信息框,默认1:页面层2:iframe层3:加载层4:tips层
                    area: ['650px', '620px'],
                    fixed: false, //不固定
                    shade: 'background-color: rgba(0,0,0,.5)',
                    shadeClose: true,
                    //maxmin: true,
                    content: 'edit?d_id=' + data.d_id + '&' + 'a_name=' + data.a_name + '&' + 'a_id=' + data.a_id + '&' + 'd_name=' + data.d_name + '&' + 'd_status=' + data.d_status + '&' + 'd_parid=' + data.d_parid + '&' + 'd_level=' + data.d_level,
                    btn: ['提交','返回'],
                    yes: function (index, layero) {
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象,执行iframe页的方法:iframeWin.method();
                        iframeWin.Buttun_Submit();//执行iframe页的方法:iframeWin.method();
                        window.location.reload();//直接页面刷新
                        //console.log(body.html()) //得到iframe页的body内容
                        //body.find('input').val('Hi,我是从父页来的')
                    },
                    btn2:function (index, layero) {
                        layer.close(index); //如果设定了yes回调,需进行手工关闭
                    },
                    
                });
            }
    

    子页面

        function  Buttun_Submit() {
            var inputName = document.getElementById('selectname').value;//部门名称(判空)
            var dId = d_id;//部门id
            var pId = document.getElementById('selectID').value;//上级部门id
            var aId = document.getElementById('AreaselectID').value;//所在地区id
            if (dId == pId) {
                layer.msg("上级部门选择错误!");
            } else {
                $.ajax({
                    url: "/sys_department/edit_detaile",//请求地址
                    dataType: "json",//数据格式
                    type: "POST",//请求方式
                    async: false,//是否异步请求
                    data: {
                        inputName: inputName,
                        dId: dId,
                        pId: pId,
                        aId: aId
                    },
                    success: function (data) {
                        layer.msg(data);
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name)
                            parent.layer.close(index);
                        }, 500);
                    },
                });
            }
            
        }
    
    

    借鉴文章:
    https://fly.layui.com/jie/61122/
    https://www.cnblogs.com/zhaow/p/9753836.html
    https://www.layui.com/doc/modules/layer.html

  • 相关阅读:
    POJ 2018 二分
    873. Length of Longest Fibonacci Subsequence
    847. Shortest Path Visiting All Nodes
    838. Push Dominoes
    813. Largest Sum of Averages
    801. Minimum Swaps To Make Sequences Increasing
    790. Domino and Tromino Tiling
    764. Largest Plus Sign
    Weekly Contest 128
    746. Min Cost Climbing Stairs
  • 原文地址:https://www.cnblogs.com/jsll/p/12518408.html
Copyright © 2011-2022 走看看