javascript - 范围内的 SurroundContents 跨越多个标签(getRangeAt 问题?)

标签 javascript text range selection

我有一个脚本(我认为)需要使用 surroundContents 来包裹选择区域。这样做允许我附加一些东西,然后将范围重新分配为选择。

我相信我已经将问题缩小到对 getRangeAt 的误用,但我不太确定如何纠正它。

这是简短的代码:

        function getRangeObject(selectionObject) {
        // Moz
        if (selectionObject.getRangeAt) {
            return selectionObject.getRangeAt(0);
        }

这是第 89 行,它向我抛出一个错误:

rangeObject.surroundContents(newNode);

当然,这是错误:

Error: uncaught exception: [Exception... "The boundary-points of a range does not meet specific requirements." code: "1" nsresult: "0x805c0001 (NS_ERROR_DOM_RANGE_BAD_BOUNDARYPOINTS_ERR)" location: "http://www.latentmotion.com/insertNode/index26.html Line: 89"]

如果对查看整个内容有帮助,您可以在此处查看脚本(到目前为止): http://www.latentmotion.com/insertNode/index26.html

我要使用的文本选择助手是 quirksmode - 它没有详细说明多个范围的使用,located here .

预先感谢您的帮助。

最佳答案

我认为错误消息很好地描述了问题。 This section of the DOM Range spec描述了在使用 surroundContents 时导致 Range 抛出异常的原因。

关于javascript - 范围内的 SurroundContents 跨越多个标签(getRangeAt 问题?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1617180/

相关文章:

python - 无法使用灵活类型 plt.hist 执行 reduce

Android:任何设备上文本框中的字体大小不能大于 717px

php - 如何对单个表中的多行进行分组并获取给定范围内的所有记录

google-app-engine - Google App Engine - IP 地址列表?

c++ - 如何在 C++ 中找到第一个最大值?

javascript - AngularJS、AngularConfirm - 功能完成后更新确认对话框

javascript - 拉斐尔·Javascript

javascript - react 应用程序错误 'Uncaught ReferenceError: React is not defined'

javascript - 多个单选按钮组相互干扰

java - 如何在 FXML 文件中将文本分成多行并附加它们