nodelist 从哪里来 ?
nodelist 集合主要是从node.childNodes 和 document.querySelectorAll('') 产生的节点集合.
题外:
1.childNodes 和 children 区别在于childNodes 返回的节点包括文本、元素、属性节点。children 返回的是节点元素的集合。
2. nodelist , htmlcollection. 这两个都是返回节点的集合,区别是nodelist 可能包含文本、元素、属性节点,而 hmtlcollection 返回的是节点元素。 htmlcollection 比 nodelist 对象多一个.nameItem(id/name)获取接单的信息

node.childNodes 返回是一个实时的节点集合。也就是说如果文档节点变化了,它也会跟着变化。而使用document.querySelectorAll()产生的节点集合确实静态的。
nodelist 怎么使用数组的方法。
1. 直接使用for 循环语句。

2. Array.prototype.slice.call 或者 [].slice.call 该方法ie8以下不支持

参考资料:https://developer.mozilla.org/zh-CN/docs/Web/API/NodeList
网友评论