NodeIterator.previousNode()
method returns the previous node in the set represented by the
NodeIterator
and moves the position of the iterator backwards within the set.
此方法返回
null
when the current node is the first node in the set.
In old browsers, as specified in old versions of the specifications, the method may throws the
INVALID_STATE_ERR
DOMException
if this method is called after the
NodeIterator.detach()
method. Recent browsers never throw.
node = nodeIterator.previousNode();
var nodeIterator = document.createNodeIterator(
document.body,
NodeFilter.SHOW_ELEMENT,
{ acceptNode: function(node) { return NodeFilter.FILTER_ACCEPT; } },
false // this optional argument is not used any more
);
currentNode = nodeIterator.nextNode(); // returns the next node
previousNode = nodeIterator.previousNode(); // same result, since we backtracked to the previous node
| 规范 | 状态 | 注释 |
|---|---|---|
|
DOM
The definition of 'NodeIterator.previousNode' in that specification. |
实时标准 |
As
detach()
is now a no-op method, this method cannot throw anymore.
|
|
Document Object Model (DOM) Level 2 Traversal and Range Specification
The definition of 'NodeIterator.previousNode' in that specification. |
过时 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
previousNode
|
Chrome 1 | Edge 12 | Firefox 3.5 | IE 9 | Opera 9 | Safari 3 | WebView Android Yes | Chrome Android Yes | Firefox Android 4 | Opera Android 10.1 | Safari iOS 3 | Samsung Internet Android Yes |
完整支持
NodeIterator
.
NodeIterator
detach()
nextNode()
previousNode()
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
NodeList
NonDocumentTypeChildNode
ProcessingInstruction
PromiseResolver
范围
StaticRange
文本
TextDecoder
TextEncoder
TimeRanges
TreeWalker
TypeInfo
USVString
UserDataHandler
XMLDocument