我有一个脚本(我认为)需要使用 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/