Layer获取iframe的dom元素及调用iframe页的js方法

1. 父页面点击第一个按钮触发,获取子页面中的body元素,调用子页面中定义的js方法

yes : function(index,layero){
    //获取iframe的body元素
    var body = layer.getChildFrame('body',index);
    //得到iframe页的窗口对象
    var iframeWin = window[layero.find('iframe')[0]['name']]; 
    //执行iframe页的showMsg方法
    iframeWin.showMsg("mercy");
                    
    console.log(iframeWin);
    console.log("yes回调函数中:"+body.html());
    console.log(layero,index);
}

2. 子页面定义的showMsg()方法:

<script type="text/javascript">
 
    function showMsg(msg){
        layer.msg(msg);
    }
</script>

猜你喜欢

转载自www.cnblogs.com/lxl57610/p/10971952.html