layer.open({ type: 2, title: '我是子iframe页面', shadeClose: true, shade: 0.8, area: ['380px', '90%'], content: './son.html', //iframe的url success:function(dom){ let $iframeDom=$(dom[0]).find("iframe").eq(0).contents(); $iframeDom.find("#test").html("我是从父级传来的值哟……") } });
示例代码:
father.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>父级页面</title> <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> <script src="https://www.jb51.net/layer.js"></script> <style> .btn{display:inline-block;height:30px;line-height:30px;border-radius:5px;background:darkturquoise;padding:5px 12px;color:#fff;cursor:pointer;margin-right:20px;} </style> </head> <body> <div> <span>layer弹出iframe层</span> </div> <iframe src="https://www.jb51.net/son.html" frameborder="0"></iframe> <script> $("#father_dataChange").click(function () { layer.open({ id:"son", type: 2, title: '我是子iframe页面', shadeClose: true, shade: 0.8, area: ['380px', '90%'], content: './son.html', success:function(dom){ let $iframeDom=$(dom[0]).find("iframe").eq(0).contents(); $iframeDom.find("#test").html("我是从父级传来的值哟……") } }); }) </script> </body> </html>
son.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>子级页面</title> <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> </head> <body> <div></div> </body> </html>