DOM范围克隆不受DOM更改的影响 [英] DOM Range clones are not immune to DOM changes
问题描述
我正在使用cloneRange()函数克隆DOM Range。如果然后我像这样修改原始范围对象:
I am making a clone of a DOM Range using cloneRange() function. If I then modify the original range object like this:
range.setStart(range.startContainer, 1);
克隆将按预期保留旧的 startOffset
。
The clone preserves the old startOffset
as expected.
但是,如果我修改DOM树,则克隆的 startOffset
也将受到影响。
However, if I modify the DOM tree, then the clone's startOffset
will also get affected. Is there an intentional internal wiring between the DOM tree and all ranges that are associated with it (clones included)?
推荐答案
是的。在 DOM 2级范围规范。最新的 DOM4范围规范在变异算法部分(感谢RobG指出了这一点)。
Yes, there is. What happens to ranges under DOM mutation is specified in the DOM Level 2 Range specification. The more recent DOM4 Range specification specifies this under the mutation algorithms section (thanks to RobG for pointing that out).
这篇关于DOM范围克隆不受DOM更改的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!