【发布时间】:2015-08-09 18:53:33
【问题描述】:
由于我不会进入的原因,我需要在页面中使用 iframe(我知道它们已经过时等等)。我还需要使用 javascript 在 iframe 之前插入链接。
根据 W3 学校,这应该很容易:
var newItem = document.createElement("LI"); // Create a <li> node
var textnode = document.createTextNode("Water"); // Create a text node
newItem.appendChild(textnode); // Append the text to <li>
var list = document.getElementById("myList"); // Get the <ul> element to insert a new node
list.insertBefore(newItem, list.childNodes[0]); // Insert <li> before the first child of <ul>
但是,这似乎适用于除 iframe 之外的每个 html 元素?
谁能解释一下如何做到这一点,或者至少为什么它不适用于 iframe。
【问题讨论】:
-
“但是,这似乎适用于除 iframe 之外的所有 html 元素?” 是什么让您认为它不适用于 iframe?在寻求帮助时,不要引用可以工作的代码,而是引用你尝试过的没有工作的代码。
insertBefore与iframes配合得很好,所以问题出在你没有显示的代码上。
标签: javascript html iframe