何时调用"DOMNodeInserted"事件?

Lai*_*uan 5 javascript dom dom-events dom-node

DOMNodeInserted 当节点"被追加到"或"被追加"时调用event?

我问这个是因为以下代码:

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

    if (container.addEventListener) {
        container.addEventListener ('DOMNodeInserted', OnNodeInserted, false);
    }
    container.appendChild (textNode);
}
Run Code Online (Sandbox Code Playgroud)

然后:

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

   if (textNode.addEventListener) {
       textNode.addEventListener ('DOMNodeInserted', OnNodeInserted, false);
   }
   container.appendChild (textNode);
}
Run Code Online (Sandbox Code Playgroud)

两者都OnNodeInserted在Chrome中调用.这是一个错误吗?

Man*_*eUK 9

这是来自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
Run Code Online (Sandbox Code Playgroud)

关键是Bubbles:是的 - 这也就是为什么它也会被放在容器上.