javascript – 为什么DOM树oder预订,深度优先遍历?

前端之家收集整理的这篇文章主要介绍了javascript – 为什么DOM树oder预订,深度优先遍历?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
为什么DOM树oder预订,深度优先遍历?

与其他遍历如BFT相比,此设计选择有哪些优势?

我只是在研究DOM standard并找到了前后的定义:

An object A is preceding an object B if A and B are in the same tree
and A comes before B in tree order.

An object A is following an object B if A and B are in the same tree
and A comes after B in tree order.

Just like most programming paradigms the Web platform has finite
hierarchical tree structures,simply named trees. The tree order is
preorder,depth-first traversal.

解决方法

深度优先遍历通常是最简单的遍历样式,因为您可以递归或使用显式堆栈执行此操作;广度优先需要一个队列,在某种意义上,这是一个更复杂的数据结构.但我认为答案比传统或简单更简单:(X)HTML树的深度搜索遍历导致文本节点以呈现顺序遍历.

考虑这个相对简单的HTML子树.

或者,以原始形式:

<p>Consider this <emph>relatively</emph> simple <a href="...">HTML</a> subtree</p>

作为一棵树(省略空白和属性):

<P>
                       |
      +-----------+----+----+-----+------+               
______|______   __|___   ___|__  _|_  ___|___
Consider this   <EMPH>   simple  <A>  subtree
                  |               |
              ____|_____        __|__
              relatively         HTML

深度优先遍历:

<P>,Consider this,<EMPH>,relatively,simple,<A>,HTML,subtree

广度优先遍历:

<P>,subtree,HTML
原文链接:https://www.f2er.com/js/154340.html

猜你在找的JavaScript相关文章