[英]When is “DOMNodeInserted” event called?
DOMNodeInserted
event is called when the node "be appended to", or "be appended"? 当节点“附加到”或“附加”时,将调用
DOMNodeInserted
事件吗?
I ask this because the following code: 我问这是因为以下代码:
function AddTextToContainer () {
var textNode = document.createTextNode ("My text");
var container = document.getElementById ("container");
if (container.addEventListener) {
container.addEventListener ('DOMNodeInserted', OnNodeInserted, false);
}
container.appendChild (textNode);
}
and that: 然后:
function AddTextToContainer () {
var textNode = document.createTextNode ("My text");
var container = document.getElementById ("container");
if (textNode.addEventListener) {
textNode.addEventListener ('DOMNodeInserted', OnNodeInserted, false);
}
container.appendChild (textNode);
}
Both invoke OnNodeInserted
in Chrome. 两者都在Chrome中调用
OnNodeInserted
。 Is it a bug? 是虫子吗?
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
The key is the Bubbles: Yes - thats why its being fired on the container as well. 关键是气泡:是的 -这就是为什么它也要在容器上射击的原因。
If you want to prevent the event from bubbling up just use event.stopPropagation(); 如果要防止事件冒泡,请使用event.stopPropagation();。 in your text node callback.
在您的文本节点回调中。 Events are then no longer handled up the dom tree.
然后,事件不再在dom树上处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.