有人可以向我解释一下为什么吗
var Node = document.createElement("testing");
var Parent = document.createElement("testingOne")
Parent.appendChild(document.createElement("hi"));
Node.appendChild(Parent);
产生与
不同的结果var Node = document.createElement("testing");
var Parent = document.createElement("testingOne")
.appendChild(document.createElement("hi"));
Node.appendChild(Parent);
在第二个片段中,甚至没有包含元素testingOne。为什么管道会这样做?
最佳答案
您的第一个示例将导致
<testing><testingone><hi></hi></testingone></testing>
Parent
将包含 testingOne
且 hi
元素将附加到其上。
虽然第二个示例将导致
<testing><hi></hi></testing>
因为 Parent
将包含 hi
元素,该元素由 appendChild
方法返回。
关于javascript - JavaScript 中的管道 createElement 和appendChild,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23985797/