主要不同在于:
- HTMLCollection 是元素集合
- NodeList 是节点集合。我们已知 js 节点分为了元素节点、文本节点、属性节点。所以node.childNodes 返回 NodeList,其中就包含了元素节点和空白的文本节点。而 node.children 或 node.getElementsBy~ 返回 HTMLCollection
假设当前存在这样的文档结构:
<ul id="left_list"><li>list 1</li><li>list 2</li><li>list 3</li><li>list 4</li><li>list 5</li></ul>
现在分别打印 childNodes、byTagName 和 children :

另外还需要注意的一点是,HTML5 新增的 querySelectorAll 返回的虽然是 NodeList ,但实际上是元素集合,并且是静态的,即,文档结构发生改变,其长度不会发生变化。其他接口返回的 HTMLCollection 和 NodeList 都是动态、实时的。
