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中调用.这是一个错误吗?
这是来自W3C
Run Code Online (Sandbox Code Playgroud)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:是的 - 这也就是为什么它也会被放在容器上.
归档时间: |
|
查看次数: |
4582 次 |
最近记录: |