JS 到底是怎么对待 AtributeNode(元素节点)和其它更加非主流的节点的?为何 childNodes 不包含它们? JS 的 childNodes 只认元素节点、文本节点吗?

2017-09-25 17:05:50 +08:00
 Newyorkcity
谢谢
1091 次点击
所在节点    问与答
2 条回复
noe132
2017-09-25 17:21:18 +08:00
The Attr node inherits from Node, but is not considered a part of the document tree. Common Node attributes like parentNode, previousSibling, and nextSibling are null for an Attr node. You can, however, get the element to which the attribute belongs with the ownerElement property.

children is a HTMLCollection, which is an ordered collection of DOM elements that are children of node. If there are no element children, then children contains no elements and has a length of 0.

children 只包含 dom nodes。The Attr node inherits from Node, but is not considered a part of the document tree

https://developer.mozilla.org/en-US/docs/Web/API/element/getAttributeNode
https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/children
Newyorkcity
2017-09-25 18:05:27 +08:00
@noe132 我去寻找了一下 document tree 的知识,想确定 nodeType 总共 12 个值对应 12 种 node,到底哪些是被 document tree 认可并且收入树模型里的,但没找到,请问你有相关资料吗?
另外这个过程里我看了 nodeType 的资料 https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType,其中声明 ATTRIBUTE_NODE 等元素『已被弃用』……我现在推测是不是哪些在被弃用列表中的 node 都不会再进入 document tree 了呢?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/393487

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX