编程语言
首页 > 编程语言> > javascript – IE 11上的MutationObserver语法错误

javascript – IE 11上的MutationObserver语法错误

作者:互联网

当我切换面板的内容时,我正在使用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()上.我不知道发生了什么.提前致谢.

enter image description here

以防万一,这是我的“目标”:

var target = $('.tab-content > .tab-pane').get(0);

解决方法:

使用MutationObserver,可以过滤属性,但前提是您要观察元素属性.因此,选项attributeFilter仅在属性设置为true时适用.

如果指定attributeFilter而不将属性设置为true,那么IE11将抛出语法错误,而Chrome和Firefox将默默地忽略attributeFilter.

要解决语法错误,请将attributes设置为true或删除attributeFilter.

标签:javascript,internet-explorer,syntax-error,mutation-observers
来源: https://codeday.me/bug/20190611/1215979.html