欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-10-25 14:28:44
1. 父页面点击第一个按钮触发,获取子页面中的body元素,调用子页面中定义的js方法 yes : function(index,layero){ //获取iframe的...

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>