【问题标题】:can any one explain this one with small examples [duplicate]任何人都可以用小例子来解释这个[重复]
【发布时间】:2013-10-21 12:04:11
【问题描述】:

javascript中的nodelist和array有什么区别?我们可以将数组转换为节点列表吗?

【问题讨论】:

标签: javascript


【解决方案1】:

我最多可以给你参考:

nodeList

NodeList 对象是 Node.childNodes 返回的节点的集合 和 querySelectorAll 方法。

Array

JavaScript Array 全局对象是数组的构造函数,它 是高级的、类似列表的对象。

这是 David Walsh 的博客:Convert NodeList to Array,其中建议:

var nodesArray = Array.prototype.slice.call(document.querySelectorAll("div"));

【讨论】:

  • 问题在于它们之间的区别,而不是“它是什么”
  • 一旦用户知道两者是什么,那么就很容易识别差异
  • 特别是来自MDN NodeList page:NodeList.prototype contains the item method, but none of the Array.prototype methods, so they cannot be used on NodeLists.
  • 我是来找Array->NodeList的。
猜你喜欢
  • 2020-09-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-19
  • 2019-06-02
相关资源
最近更新 更多