Javascript Firefox不遵守Observer中的childList配置参数
以下是我如何声明我的突变观察者:Javascript Firefox不遵守Observer中的childList配置参数,javascript,html,mutation-observers,Javascript,Html,Mutation Observers,以下是我如何声明我的突变观察者: observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { switch (mutation.type) { case 'childList': // Do Stuff break; } }) observer
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(V29.0.1)中,观察者仅在元素直接添加到观察到的元素而不是其子元素时才会触发。为什么?你忘了把
subtree: true
应该是
document.getElementById('contentEditableElement'),
{
attributes: false,
childList: true,
characterData: false,
subtree: true
}
将属性和characterData设置为true时会发生什么情况?您的代码与moz示例非常相似:行为没有变化。