原生js操作iframe标签引入的页面的DOM元素方法

<iframe id="ifr" src="test.html"></iframe>    // 父级页面的iframe

let iframe = document.getElementById("ifr");    
let testchild = iframe.contentWindow.document.getElementById("test");    // 重点:contentWindow

以上代码即可获取iframe标签引入的页面中的元素,获取到之后想要怎么操作就怎么操作了。

猜你喜欢

转载自blog.csdn.net/joyvonlee/article/details/84373158