javascript - 如何修复错误 "Selection.addRange()"?

标签 javascript html css ruby-on-rails google-chrome

我需要帮助来修复此错误:

The behavior that Selection.addRange() merges existing Range and the specified Range is deprecated and will be removed in M58, around April 2017. See https://www.chromestatus.com/features/6680566019653632 for more details.

我无法编辑或销毁我网站的元素。

最佳答案

来自this Github issue ,现在您必须调用removeAllRanges()在将范围添加到您的选择之前:

selection = window.getSelection();    // Save the selection.
range = document.createRange();
range.selectNodeContents(elem);
selection.removeAllRanges();          // Remove all ranges from the selection.
selection.addRange(range);            // Add the new range.

关于javascript - 如何修复错误 "Selection.addRange()"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43415498/

相关文章:

javascript - 两个仪表在一整圈内

jquery - Bootstrap 嵌套 Accordion 字体-很棒的图标

html - 当我从 html 转换为 PDF 时,换行符没有出现在转换后的 PDF 页面中,正如我在 HTML 页面中看到的那样

javascript - float div 周围的暗区

javascript - JSONPath 作为单独的 JSON 排除

html - 如何在 Zurb Foundation 6 中将背景图像添加到 HTML 电子邮件中

jquery - 使用内联代码更改悬停时的图像

javascript - 在一些 jquery wordpress 中 Hook 时遇到问题

css - .field_with_errors 弄乱了 Bootstrap 样式的表单

javascript - 使用 JavaScript 缩放至全窗口宽度