iframe标签用来嵌套子页面。css
一个iframe就至关于一个新的窗口。浏览器
在父页面中不能给iframe页面中的DOM对象添加事件,反之亦然。服务器
iframe中的DOM没法正常获取,需以下写:code
父页面中获取iframe子页面中的元素:对象
window.frames["iframe的name值"].document.querySelector("css选择器");事件
iframe子页面获取父页面中的元素 :iframe
window.parent.document.document.querySelector("css选择器");css选择器
例如di
window.frames["iframeName"].document.querySelector(".div"); window.parent.document.document.querySelector("#div");