2011-11-26 20 views
5

DOMNodeInserted Düğüm, düğüm eklendiğinde veya "eklensin" durumunda mı çağrılır?"DOMNodeInserted" olayı ne zaman çağrıldı?

Aşağıdaki kodu çünkü bu sorun:

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

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

ve bu:

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

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

İkisi Chrome'da OnNodeInserted çağırmak. Bu bir hata mı?

cevap

9

Bu 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 

anahtar Bubbles geçerli: Evet - onun yanı kabın üzerine ateş olmak thats neden.

-1

Etkinliğin köpürmesini önlemek istiyorsanız, event.stopPropagation(); metin düğümünde geri arama. Olaylar artık dom ağaca taşınmaz.

+0

'event.stopPropagation()' Benim için herhangi bir etkisi yok gibi görünüyor. Olay hala hedef çocukların çocukları için ateş ediyor. Ben 'event.target' olduğunu düşündüğüm nesne olduğunu kontrol ederek etrafında çalıştım. – devios1

İlgili konular