在DOM Level 1 Core中,Text.splitText被定义为……
Breaks this Text node into two Text nodes at the specified offset,keeping both in the tree as siblings. This node then only contains all the content up to the offset point. And a new Text node,which is inserted as the next sibling of this node,contains all the content at and after the offset point.
标准化是……
Puts all Text nodes in the full depth of the sub-tree underneath this Element into a “normal” form where only markup (e.g.,tags,comments,processing instructions,CDATA sections,and entity references) separates Text nodes,i.e.,there are no adjacent Text nodes. This can be used to ensure that the DOM view of a document is the same as if it were saved and re-loaded,and is useful when operations (such as XPointer lookups) that depend on a particular document tree structure are to be used.
所以,如果我采用一个包含“Hello World”的文本节点,在textNode中引用,并且执行
textNode.splitText(3)
textNode现在具有内容“Hello”,以及包含“World”的新兄弟
如果我那么
textNode.parent.normalize()
什么是textNode?该规范没有明确表示textNode仍然是它的前一个父节点的子节点,只是更新为包含所有相邻的文本节点(然后被删除).它似乎是一个删除所有相邻文本节点的一个conforment行为,然后重新创建一个具有值的串联的新节点,使textNode指向不再是树的一部分的东西.或者,我们可以以与splitText相同的方式更新textNode,因此它保留了它的树位置,并获得了一个新值.
行为的选择实际上是完全不同的,我无法找到关于哪个是正确的澄清,或者这只是规范中的疏忽(它似乎在2级或3级似乎没有澄清).任何DOM / XML专家都可以解决这个问题吗?
如有疑问,请采取防御措施.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。