我有一个看起来像这样的iframe:
<iframe id="iframe2" ...>
#document
<html>...</html>
</iframe>
我正在尝试获取带有 html
标签的 iframe
下方的项目。
在 JavaScript 中,当我执行以下操作时:
document.getElementByID("iframe2")
这将返回正确的iframe。
然而,当我执行以下操作时:
document.getElementByID("iframe2").childNodes
返回值为[]
。
document.getElementByID("iframe2").getElementsByTagName("#document")
和document.getElementByID("iframe2").getElementsByTagName("html")
也返回[]
。
如何访问html
标签?
此外,那个#document
标签叫什么?
#document
不是真正的子节点;它是由Chrome开发工具(可能还包括Firebug)插入的占位符,代表iframe的contentDocument
属性。 - apsillers