这应该是我们在开发中经常用到的吧,主窗口和Iframe层之间传值实现我们各种需求,比如打开某条记录的详细数据….
主窗口向Iframe层传值方式一:
//主窗口代码
layer.open({
type: 2,
title: "标题",
shade: 0.5,
area: ['500px', '500px'],
anim: 2,
content: ['url'],
success: function (layero, index) {
var iframe = window['layui-layer-iframe' + index];//拿到iframe元素
iframe.child(JSON.stringify(data))//向此iframe层方法 传递参数
}
});
//iframe层代码
主窗口向Iframe层传值方式二:
//主窗口代码
content: ['url?a=1?b=2'],
//iframe层代码
var a=window.location.href.split('?')[1].replace("a=", "");
var b=window.location.href.split('?')[2].replace("b=", "");iframe层向主窗口传值就比较简单了
parent.$("#主窗口元素ID").val("需要传递的参数");
未经允许不得转载:作者:刘天佑,
转载或复制请以 超链接形式 并注明出处 刘天佑博客-记录生活和成长的一个自媒体博客。
原文地址:《Layui主窗口和Iframe层参数传递》 发布于2018-08-20
评论 抢沙发