当我切换面板的内容时,我正在使用MutationObserver来更改某些变量的值(我正在使用Bootstrap选项卡)。在Chrome和Firefox中,一切都运行得很好,但出于某种原因,当我用IE测试它时,它在控制台中显示语法错误并且脚本中断。这是我的MutationObserver代码:
var observer = new MutationObserver(function (MutationRecords, MutationObserver) {
dataTable = null;
tabla = null;
tabActiva = $('.tab-content').find('.active');
formFiltro = tabActiva.find('form');
tabla = tabActiva.find('table');
});
observer.observe(target, {
childList: true,
attributeFilter: ['class'],
subtree: true
});
控制台指出错误在observer.observe()上。我不知道发生了什么。提前谢谢。
以防万一,这是我的“目标”:
var target = $('.tab-content > .tab-pane').get(0);
答案 0 :(得分:5)
使用MutationObserver
,可以过滤属性,但前提是您要观察元素属性。因此,选项attributeFilter
仅在attributes
设置为true
时适用。
如果您指定attributeFilter
但未将attributes
设置为true
,则IE11将抛出语法错误,而Chrome和Firefox将默默忽略attributeFilter
。
要解决语法错误,请将attributes
设置为true
或删除attributeFilter
。
答案 1 :(得分:2)
attributeFilter
属性,则没有必要,也暗示将
attributes
设置为true
。
attributeFilter
定义为如果不是全部,则设置为属性本地名称(无名称空间)的列表 需要观察属性突变,并且
attributes
是true
或 省略。
attributeFilter
和attributes: true
。