Range.setEnd()
method sets the end position of a
范围
to be located at the given offset into the specified node x.Setting the end point above (higher in the document) than the start point will result in a collapsed range with the start and end points both set to the specified end position.
range.setEnd(endNode, endOffset);
endNode
节点
inside which the
范围
should end.
endOffset
范围
from the start of
endNode
.
undefined
.
Exceptions are thrown as
DOMException
objects of the following types:
InvalidNodeTypeError
endNode
is a doctype node; range endpoints cannot be located inside a doctype node.
IndexSizeError
endOffset
is either greater than or equal to the length of the node or is less than zero.
若
endNode
是
节点
类型
文本
,
注释
,或
CDataSection
,那么
endOffset
is the number of characters from the start of
endNode
. For other
节点
类型,
endOffset
is the number of child nodes between the start of the
endNode
.
const range = document.createRange();
const endNode = document.getElementsByTagName('p').item(3);
const endOffset = endNode.childNodes.length;
range.setEnd(endNode, endOffset);
setEnd()
is commonly used in conjunction with
setStart()
to fully configure a range.
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
setEnd
|
Chrome Yes | Edge 12 | Firefox 4 | IE 9 | Opera 9 | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android 4 | Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
完整支持
范围
cloneContents()
cloneRange()
collapse()
compareBoundaryPoints()
compareNode()
comparePoint()
createContextualFragment()
deleteContents()
detach()
extractContents()
getBoundingClientRect()
getClientRects()
insertNode()
intersectsNode()
isPointInRange()
selectNode()
selectNodeContents()
setEnd()
setEndAfter()
setEndBefore()
setStart()
setStartAfter()
setStartBefore()
surroundContents()
toString()
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
NodeList
NonDocumentTypeChildNode
ProcessingInstruction
PromiseResolver
StaticRange
文本
TextDecoder
TextEncoder
TimeRanges
TreeWalker
TypeInfo
USVString
UserDataHandler
XMLDocument