Returns a node from a
NodeList
by index. This method doesn't throw exceptions as long as you provide arguments. A value of
null
is returned if the index is out of range, and a
TypeError
is thrown if no argument is provided.
nodeItem = nodeList.item(index)
nodeList
是
NodeList
. This is usually obtained from another DOM property or method, such as
childNodes
.
index
is the index of the node to be fetched. The index is zero-based.
nodeItem
是
index
th node in the
nodeList
返回通过
item
方法。
JavaScript also offers an array-like bracketed syntax for obtaining an item from a NodeList by index:
nodeItem = nodeList[index]
var tables = document.getElementsByTagName("table");
var firstTable = tables.item(1); // or simply tables[1] - returns the second table in the DOM
| 规范 | 状态 | 注释 |
|---|---|---|
|
DOM
The definition of 'NodeList: item' in that specification. |
实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
item
|
Chrome 1 | Edge 12 | Firefox Yes | IE ? | Opera Yes | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android Yes | Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
完整支持
兼容性未知
NodeList
AbortController
AbortSignal
AbstractRange
Attr
ByteString
CDATASection
CSSPrimitiveValue
CSSValue
CSSValueList
CharacterData
ChildNode
注释
CustomEvent
DOMConfiguration
DOMError
DOMErrorHandler
DOMException
DOMImplementation
DOMImplementationList
DOMImplementationRegistry
DOMImplementationSource
DOMLocator
DOMObject
DOMParser
DOMPoint
DOMPointInit
DOMPointReadOnly
DOMRect
DOMString
DOMTimeStamp
DOMTokenList
DOMUserData
Document
DocumentFragment
DocumentType
元素
ElementTraversal
Entity
EntityReference
事件
EventTarget
HTMLCollection
MutationObserver
节点
NodeFilter
NodeIterator
NonDocumentTypeChildNode
ProcessingInstruction
PromiseResolver
范围
StaticRange
文本
TextDecoder
TextEncoder
TimeRanges
TreeWalker
TypeInfo
USVString
UserDataHandler
XMLDocument