Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在填充页面中的所有 TextNode,使用 ajax 查询将它们的 nodeValues 发布到远程站点。当调用关联的回调时,我想以某种方式标记提供给回调函数的 TextNode,但 TextNode 的属性似乎是不可变的,除了 nodeValue。
我现在能想到的许多选项是以某种方式标记 nodeValue 而不更改看到的文本 - 使用不可打印的字符?或包装 TextNode 对象/类,将其从 dom 树中删除并将其重新注入 dom 树?
这些可行吗?你还有其它的想法吗?
提前致谢。
我能想到的另一个想法是用表单中的对象填充数组{'element': text element, 'read': 0}。当您读入一个 textNode 时,对数组中的所有对象执行循环,直到找到与该element属性匹配的对象。然后将read值设置为 1。如果要检查是否已读取文本元素,则需要再次循环遍历数组,直到找到与element属性匹配的元素并查看read值是什么。如果您有很多文本节点,这将变得昂贵。
{'element': text element, 'read': 0}
element
read