【发布时间】:2013-10-21 12:04:11
【问题描述】:
javascript中的nodelist和array有什么区别?我们可以将数组转换为节点列表吗?
【问题讨论】:
-
检查此转换...davidwalsh.name/nodelist-array
标签: javascript
javascript中的nodelist和array有什么区别?我们可以将数组转换为节点列表吗?
【问题讨论】:
标签: javascript
我最多可以给你参考:
NodeList 对象是 Node.childNodes 返回的节点的集合 和 querySelectorAll 方法。
JavaScript Array 全局对象是数组的构造函数,它 是高级的、类似列表的对象。
这是 David Walsh 的博客:Convert NodeList to Array,其中建议:
var nodesArray = Array.prototype.slice.call(document.querySelectorAll("div"));
【讨论】:
NodeList.prototype contains the item method, but none of the Array.prototype methods, so they cannot be used on NodeLists.
Array->NodeList的。