我想在一個文件,看起來有點像這樣的最頂端插入一段HTML中找到:節點沒有發現錯誤,儘管節點可以在控制檯
<html>
<frameset onunload="unload()" onload="loadme()" id="topframeset" frameborder="0" framespacing="0" rows="45,19,10,0,*,22">
(...)
</frameset>
</html>
OK - 似乎很容易。在Firebug中,我可以這樣做:
>>> document.getElementById("topframeset")
<frameset id="topframeset" onunload="unload()" onload="loadme()" frameborder="0" framespacing="0" rows="45,19,10,0,*,22">
所以它認爲它很好。
然後:
document.insertBefore(document.createTextNode("<h1>hello</h1>"), document.getElementById("topframeset"))
Error: Node was not found
[Break On This Error]
...ertBefore(document.createTextNode("<h1>hello</h1>"), document.getElementById("to...
這是怎麼回事?
也許這是因爲您試圖構建無效的HTML結構。 Frameset不能有'h1'兄弟。 http://www.w3.org/TR/html4/present/frames.html#h-16.2.1 – dfsq
我想這可能是。那麼在文檔中真的不可能有什麼但