如何获取HTML文档中的所有文本节点? [重复]

时间:2022-06-16 19:42:52

This question already has an answer here:

这个问题在这里已有答案:

Is there a way to get all text nodes in a HTML document? I mean something like

有没有办法在HTML文档中获取所有文本节点?我的意思是

document.getElementsByTagName("div")

but for text nodes?

但对于文本节点?

Or, do I have to walk the DOM to get them?

或者,我是否必须使用DOM来获取它们?

1 个解决方案

#1


1  

NodeIterator with NodeFilter.SHOW_TEXT.

NodeIterator与NodeFilter.SHOW_TEXT。

https://developer.mozilla.org/en-US/docs/Web/API/NodeIterator

#1


1  

NodeIterator with NodeFilter.SHOW_TEXT.

NodeIterator与NodeFilter.SHOW_TEXT。

https://developer.mozilla.org/en-US/docs/Web/API/NodeIterator