如何标记 HTML DOM TextNode
我正在填充页面中的所有 TextNode,并使用 ajax 查询将它们的 nodeValues 发布到远程站点。当调用关联的回调时,我想以某种方式标记提供给回调函数的 TextNode,但 TextNode 的属性似乎是不可变的,除了 nodeValue 之外。
我现在能想到的许多选项都是以某种方式标记nodeValue而不改变看到的文本 - 使用不可打印的字符?或者包装 TextNode 对象/类,将其从 dom 树中删除并将其重新注入回 dom 树?
这些可行吗?您有任何(其他)想法吗?
提前致谢。
I am populating all TextNodes in a page, posting their nodeValues to a remote site with an ajax query. When the associated callback is invoked, I want to somehow mark the TextNode fed to the callback function but the attributes of TextNode seem to be immutable except nodeValue.
A number of options that I can think of now are somehow to mark nodeValue without changing the seen text-using a non-printable character? or wrapping the TextNode object/class, removing it from dom tree and reinjecting it back to the dom tree?
Are these doable? Do you have any (other) ideas?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能想到的另一个想法是用
{'element': text element, 'read': 0}
形式的对象填充数组。当您读取 textNode 时,对数组中的所有对象执行循环,直到找到与element
属性匹配的对象。然后将read
值设置为 1。如果您想检查并查看是否已读取文本元素,则需要再次循环遍历数组,直到找到与匹配的文本元素。 >element
属性并查看read
值是什么。如果您有很多文本节点,这将变得昂贵。Another idea I could think of is to populate an array with objects in the form
{'element': text element, 'read': 0}
. When you read in a textNode, do a loop on all the objects in the array until you find one that matches theelement
property. Then set theread
value to 1. If you want to check and see if a text element has been read, you'll need to once again loop through the array until you find one that matches theelement
property and see what theread
value is. This will get expensive if you have a lot of text nodes.