Javascript 什么时候是;DOMNodeInserted";什么事?
Javascript 什么时候是;DOMNodeInserted";什么事?,javascript,dom,dom-events,dom-node,Javascript,Dom,Dom Events,Dom Node,domanodeinserted当节点“被追加到”或“被追加”时调用事件 我这样问是因为以下代码: function AddTextToContainer () { var textNode = document.createTextNode ("My text"); var container = document.getElementById ("container"); if (container.addEventListener) { conta
domanodeinserted
当节点“被追加到”或“被追加”时调用事件
我这样问是因为以下代码:
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
。这是一个bug吗?这是来自
关键是泡泡:是-这就是为什么它也会在容器上激发。如果要防止事件冒泡,只需使用event.stopPropagation();在文本节点回调中。事件将不再在dom树上处理。
event.stopPropagation()
似乎对我没有任何影响。事件仍在为目标的孩子们开火。我通过检查event.target
是我认为它是的对象来解决这个问题。
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