V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
Newyorkcity
V2EX  ›  问与答

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

  •  1
     
  •   Newyorkcity · 2017-09-25 17:05:50 +08:00 · 1022 次点击
    这是一个创建于 2405 天前的主题,其中的信息可能已经有所发展或是发生改变。
    谢谢
    2 条回复    2017-09-25 18:05:27 +08:00
    noe132
        1
    noe132  
       2017-09-25 17:21:18 +08:00 via Android   ❤️ 1
    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
        2
    Newyorkcity  
    OP
       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 了呢?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1253 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:11 · PVG 02:11 · LAX 11:11 · JFK 14:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.