自写button关闭layui弹出层的几种方法

在写layer弹层时总共用到两种方法,一种layer.open({}),一种layer.tab({}),对于弹出层的关闭前后试了很多方法,踩过很多坑,现总结如下。

layer.open({})的关闭 自写取消button

    function selectRole(){
        layer.open({
            type: 2,
            area: ['460px','200px'],
            closeBtn: 0,//不显示右上角关闭按钮
            title: false,
            fix: false, //不固定
            maxmin: false,//禁用最大化,最小化按钮
            resize: false,//禁用调整大小
            content:'lalala.html'
        });
     }
<button class="layui-btn border-radius100" onclick="closeWindow()">取消</button>
<script type="text/javascript">
    /**
     * 关闭当前弹出层
     */
    function closeWindow(){
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
</script>

layer.Tab()里面配置的iframe

layer.close()都无法关闭的页面使用

function checkRole(){
        layer.tab({
            area: ['589px','25%'],
            tab: [{
                title: '表1',
                content: '<iframe src="lalala1.html" frameborder="0" style="width: 100%;height: 97%;"></iframe>'
            }, {
                title: '表2',
                content: '<iframe src="lalala2.html" frameborder="0" style="width: 100%;height: 97%;"></iframe>'
            }, {
                title: '表3',
                content: '<iframe src="lalala3.html" frameborder="0" style="width: 100%;height: 97%;"></iframe>'
            },{
                title: '表4',
                content: '<iframe src="lalala4.html" frameborder="0" style="width: 100%;height: 97%;"></iframe>'
            }]
        });
    }

在每个单iframe页面中各有各的button,对于关闭button使用方式如下。

<button class="layui-btn border-radius100" onclick="closeWindow()">取消</button>
<script type="text/javascript">
    /**
     * 关闭当前弹出层
     */
    function closeWindow(){
        parent.layer.closeAll();
    }
</script>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值