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

时间:2009-10-24 06:29:08

标签: javascript text range selection

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

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

这是简短的代码:

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

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

rangeObject.surroundContents(newNode);

当然,这是错误:

  

错误:未捕获的异常:   [例外......“边界点   范围不符合具体要求   要求。“代码:”1“nsresult:   “0x805c0001   (NS_ERROR_DOM_RANGE_BAD_BOUNDARYPOINTS_ERR)”   地点:   “http://www.latentmotion.com/insertNode/index26.html   行:89“]

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

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

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

我认为错误消息很好地描述了问题。 This section of the DOM Range spec描述了使用RangesurroundContents引发异常的原因。