gpt4 book ai didi

javascript - 什么时候调用 "DOMNodeInserted"事件?

转载 作者:数据小太阳 更新时间:2023-10-29 06:03:20 28 4
gpt4 key购买 nike

DOMNodeInserted 当节点“被附加到”或“被附加”时调用事件?

我问这个是因为下面的代码:

function AddTextToContainer () {
var textNode = document.createTextNode ("My text");
var container = document.getElementById ("container");

if (container.addEventListener) {
container.addEventListener ('DOMNodeInserted', OnNodeInserted, false);
}
container.appendChild (textNode);
}

还有:

function AddTextToContainer () {
var textNode = document.createTextNode ("My text");
var container = document.getElementById ("container");

if (textNode.addEventListener) {
textNode.addEventListener ('DOMNodeInserted', OnNodeInserted, false);
}
container.appendChild (textNode);
}

两者 在 Chrome 中调用 OnNodeInserted。是错误吗?

最佳答案

这是来自 W3C

DOMNodeInserted
Fired when a node has been added as a child of another node.
This event is dispatched after the insertion has taken place.
The target of this event is the node being inserted.
Bubbles: Yes
Cancelable: No
Context Info: relatedNode holds the parent node

关键是 Bubbles: Yes - 这就是它也在容器上发射的原因。

关于javascript - 什么时候调用 "DOMNodeInserted"事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8277494/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com