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.
从下图中可以看出,childNodes 数组有 13 个项目。但显然“书”元素只有 6 个子节点。为什么这是不准确的?
因为childNodes返回所有子节点,包括文本节点(即使它们只包含空格)。如果您迭代子节点并输出它们nodeType,您将看到有些是元素,有些是文本。
childNodes
nodeType