获取iframe 内元素的方法

1,原生的方法

首先给iframe 设置 id 属性

var obj = document.getElementById('iframe').contentWindow;
setTimeout(function(){
	// $('#iframe').contents().find('#box').html('wohao');
        obj.document.getElementById('box').innerHTML = '222';
},0)
			    

兼容ie、火狐和谷歌,具体浏览器的版本没有去测试

2,通过jquery 方法获取

$('#iframe').contents().find('#box').html('jquery');

不兼容ie

原文地址:https://www.cnblogs.com/geek12/p/5507908.html