javascript - IE11:对象不支持属性或方法“replaceWith”
问题描述
我有一个简单的函数,可以在动态加载模式时将它们移动到模式容器中。它适用于 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 。
推荐阅读
- python - ValueError:时间数据'30 avr。2020 23:19:12' 与格式 '%d %b %Y %H:%M:%S' 不匹配
- server - 在私人服务器上安装 Roblox
- python - 用 tkinter 和 for.. 创建按钮如何知道点击了哪一个?
- c++ - 使用组合时如何使用默认构造函数?在视觉工作室
- r - 构建一个新的 geom_hurricane
- python - 如何从我刚刚创建的服务器获取文件或响应
- pandas - pandas read csv 不分隔列,列太多?
- javascript - 不能使用 .replaceWith() 第二次。我该如何更换它?
- php - 如何改进我的查询以减少执行时间,并且我仍然可以使用多个表将结果分成页面
- rust - 将程序宏代码或堆栈值编译成可执行文件?