Firefox不遵守突变观察者的childList配置参数

Firefox Not Obeying childList Config Param in Mutation Observer

本文关键字:childList 配置 参数 观察者 不遵守 突变 Firefox      更新时间:2023-09-26

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

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)中,只有当元素被直接添加到被观察的元素而不是其子元素时,观察者才会触发。为什么?

你忘了写

subtree: true

应该是

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