DOM范围克隆不受DOM更改的影响 [英] DOM Range clones are not immune to DOM changes

查看:74
本文介绍了DOM范围克隆不受DOM更改的影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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)?

JS小提琴示例

推荐答案

是的。在 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆