Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

NodeList.item

概述

根据给定的索引,返回一个 NodeList对象中包含的Node对象.

语法

nodeItem = nodeList.item(index) 
  • nodeList是一个NodeList对象.通常是由某个DOM属性或方法返回的,比如childNodes.
  • index 是给定的索引. 从0开始.
  • nodeItem 是根据索引index由item方法从nodeList中获取到的节点.

JavaScript有更简单的语法来从一个NodeList对象中获取指定索引的节点:

nodeItem = nodeList[index]

例子

var tables = document.getElementsByTagName("table"); 
var firstTable = tables.item(1); // 或者简写为tables[1],返回一个文档中的第二个table元素.

备注

如果索引越界,该方法不会抛出异常,只会返回null.

item()不是DOM元素或者DOM节点的方法,而是NodeList对象的方法.

规范

DOM Level 1 Core: NodeList.item()

DOM Level 2 Core: NodeList.item()

文档标签和贡献者

 此页面的贡献者: teoli, jsx, ziyunfei
 最后编辑者: jsx,