0

这是我声明我的突变观察者的方式:

observer = new MutationObserver(function(mutations) {
    mutations.forEach(function(mutation) {
        switch (mutation.type) {
            case 'childList':
                // Do Stuff
            break;
        }
    })

observer.observe(
    document.getElementById('contentEditableElement'), 
    {
        attributes: false, 
        childList: true, 
        characterData: false
    }
);

上面的代码在 Chrome 中运行良好。当我将 HTML 元素拖放到内容可编辑区域时,当元素直接放在被观察元素上以及将元素拖放到被观察元素的子元素中时,观察者就会触发。

在 FireFox (v 29.0.1) 中,观察者仅在元素直接添加到被观察元素而不是其子元素时触发。为什么?

4

1 回答 1

0

你忘了放

subtree: true

它应该是

document.getElementById('contentEditableElement'), 
    {
        attributes: false, 
        childList: true, 
        characterData: false,
        subtree: true
    }
于 2014-11-29T19:34:56.850 回答