gpt4 book ai didi

javascript - Cody Lindley 所说的 "nodes contained in the collection are either literally part of the live document or a snapshot of the live document"是什么意思?

转载 作者:行者123 更新时间:2023-11-28 01:11:13 25 4
gpt4 key购买 nike

我没有收到这句话:

"A collection [of DOM Nodes] can either be live or static. Meaning that the nodes contained in the collection are either literally part of the live document or a snapshot of the live document."

我特别不明白他所说的“实时文档的一部分或实时文档的快照”是什么意思。他没有就此展开。

我的第一 react

他指的是集合能够保存 (1) DOM 中仍然存在的节点(即“事件”)或 (2) 当前 DOM 中不再存在的节点,例如当您可以使用一种方法来删除节点,但也返回它删除的节点(即快照)?

他从未真正对此进行过扩展,所以我想知道我是否错过了本书前面的内容,或者只是缺少他认为读者应该具备的一些先决知识。

如果您对此有任何帮助,我们将不胜感激!谢谢。

完整摘录如下:

1.13 Grokking node collections (i.e. Nodelist & HTMLcollection)

When selecting groups of nodes from a tree (cover in chaper 3) or accessing pre-defined sets of nodes, the nodes are either placed in a NodeList (e.g. document.querySelectorAll('*')) or HTMLCollection (e.g. document.scripts). These array like (i.e. not a real Array) object collections that have the following characteristics.

  • A collection can either be live or static. Meaning that the nodes contained in the collection are either literally part of the live document or a snapshot of the live document.
  • By default nodes are sorted inside of the collection by tree order. Meaning the order matches the liner path from tree trunk to branches.
  • The collections have a length property that reflects the number of elements in the list

来自 Cody Lindley 的 Dom 启蒙: http://domenlightenment.com/

如果有帮助,进一步阅读:

节点列表:https://www.w3.org/TR/dom/#nodelist

HTML 集合:https://www.w3.org/TR/dom/#htmlcollection

最佳答案

根据我发现的信息 - 并在评论中发布 - 我总结为:

当您查询 DOM 以检索节点集合时,取决于使用的方法(IE:Document.querySelectorAll()Document.querySelect() 等) 您将获得 livestatic 节点的列表,不同之处在于对 DOM 所做的更改将反射(reflect)在 中已经存在的节点中live 集合,而如果它们在 static 集合中,则相同的更改不会影响这些相同的节点。

因此,如果您想在查询 DOM 的那一刻及时获取快照,则应使用返回 static 集合的方法。这样,如果在您使用此集合时以任何方式更改 DOM,则不会对集合中的这些元素应用任何内容。 live 集合则相反。

关于javascript - Cody Lindley 所说的 "nodes contained in the collection are either literally part of the live document or a snapshot of the live document"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37678937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com