代码之家  ›  专栏  ›  技术社区  ›  Corey P

IE11:对象不支持属性或方法“replaceWith”

  •  0
  • Corey P  · 技术社区  · 8 年前

    我有一个简单的函数,可以在动态加载模态时将模态移到模态容器中。它可以在edge、chrome和firefox上运行。但是,在ie11中,我得到一个错误:“object不支持属性或方法‘replaceWith’”。我们的客户需要IE11支持。

    是什么导致了这个错误?

    function moveModals() {
        $('#mainBody .modal').each(function () {
            if ($("#modalsContainer>#" + this.id).exists())
                $("#modalsContainer>#" + this.id)[0].replaceWith(this);
            else
                $(this).appendTo("#modalsContainer");
        });
    }
    
    1 回复  |  直到 8 年前
        1
  •  3
  •   Arash Kazemi    8 年前

    改用这个:

    $("#modalsContainer>#" + this.id).replaceWith(this);
    

    这样,您只依赖jquery(省略 [0] 从你写的)。您编写的方法是从vanilla html dom对象调用replaceWith。