创建的元素是否被视为子元素?
Is a created element, considered as a child?
在 javascript 中,如果你有这个例子:
const a = document.createElement("img");
a.src = "test.png";
document.getElementById("parent").appendChild(a);
这会给真的吗? -> document.getElementById("parent").hasChildNodes();
const a = document.createElement("img");
a.src = "https://www.gravatar.com/avatar/b4185aac47f6262b40dc8f11535a32c0?s=48&d=identicon&r=PG";
document.getElementById("parent").appendChild(a);
console.log(document.getElementById("parent").hasChildNodes());
<div id="parent"></div>
在 javascript 中,如果你有这个例子:
const a = document.createElement("img");
a.src = "test.png";
document.getElementById("parent").appendChild(a);
这会给真的吗? -> document.getElementById("parent").hasChildNodes();
const a = document.createElement("img");
a.src = "https://www.gravatar.com/avatar/b4185aac47f6262b40dc8f11535a32c0?s=48&d=identicon&r=PG";
document.getElementById("parent").appendChild(a);
console.log(document.getElementById("parent").hasChildNodes());
<div id="parent"></div>