1. iframe中不存在name和id的方法

 var iframe = document.getElementsByTagName('iframe')[0].contentWindow
 iframe.document.querySelector("#元素")

2. iframe中存在name或者id

var iframe = document.getElementById('iframeId')
iframe.querySelector("#元素")

3. 子窗口获取父窗口的元素

var iframe = window.parent.document.getElementById('iframeId')
iframe.querySelector("#元素")

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐