Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript IE11:对象不';t支持属性或方法';替换为';_Javascript_Jquery_Twitter Bootstrap_Internet Explorer - Fatal编程技术网

Javascript IE11:对象不';t支持属性或方法';替换为';

Javascript IE11:对象不';t支持属性或方法';替换为';,javascript,jquery,twitter-bootstrap,internet-explorer,Javascript,Jquery,Twitter Bootstrap,Internet Explorer,我有一个简单的函数,可以在动态加载模态时将它们移动到模态容器中。它适用于Edge、Chrome和Firefox。然而,在IE11中,我得到了一个错误:“对象不支持属性或方法‘replaceWith’”。我们的客户需要IE11支持 是什么导致了错误 function moveModals() { $('#mainBody .modal').each(function () { if ($("#modalsContainer>#" + this.id).exists()

我有一个简单的函数,可以在动态加载模态时将它们移动到模态容器中。它适用于Edge、Chrome和Firefox。然而,在IE11中,我得到了一个错误:“对象不支持属性或方法‘replaceWith’”。我们的客户需要IE11支持

是什么导致了错误

function moveModals() {
    $('#mainBody .modal').each(function () {
        if ($("#modalsContainer>#" + this.id).exists())
            $("#modalsContainer>#" + this.id)[0].replaceWith(this);
        else
            $(this).appendTo("#modalsContainer");
    });
}
改用这个:

$("#modalsContainer>#" + this.id).replaceWith(this);
这样,您只需要依赖jQuery(从您编写的代码中省略
[0]
)。您编写的方式是从vanilla HTML DOM对象调用replaceWith。

使用以下方法:

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

这样,您只需要依赖jQuery(从您编写的代码中省略
[0]
)。按照您编写的方式,您正在从香草HTML DOM对象调用replaceWith。

Arash Kazemi-正是解决方案!![0]如何导致调用普通版本而不是jQuery版本?另外,其他浏览器如何“足够聪明”而不会遇到相同的错误?@Corey:[0]在所有浏览器中返回javascript对象,而不是jquery对象。不同之处在于其他浏览器实现了
replaceWith()
,IE则没有@是的,正如我们的朋友在这里评论的那样!作为补充,jQuery在所有平台上都实现了replaceWith。当您使用[0]时,您绕过jQuery,依赖浏览器实现。Arash Kazemi-正是解决方案!![0]如何导致调用普通版本而不是jQuery版本?另外,其他浏览器如何“足够聪明”而不会遇到相同的错误?@Corey:[0]在所有浏览器中返回javascript对象,而不是jquery对象。不同之处在于其他浏览器实现了
replaceWith()
,IE则没有@是的,正如我们的朋友在这里评论的那样!作为补充,jQuery在所有平台上都实现了replaceWith。当您使用[0]时,您将绕过jQuery并依赖于浏览器实现。