您的位置:首页 > 产品设计 > UI/UE

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

2019-04-19 10:24 2646 查看

关闭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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: