Range
Range
介面代表一個文件的片段(fragment),可以包含節點及部分的文字節點。
A range can be created using the createRange()
method of the Document
object. Range objects can also be retrieved by using the getRangeAt()
(en-US) method of the Selection
(en-US) object or the caretRangeFromPoint()
(en-US) method of the Document
object.
There also is the Range()
(en-US) constructor available.
屬性
There are no inherited properties.
Range.collapsed
(en-US) Read only-
Returns a
Boolean
(en-US) indicating whether the range's start and end points are at the same position. Range.commonAncestorContainer
(en-US) Read only-
Returns the deepest
Node
that contains thestartContainer
andendContainer
nodes. Range.endContainer
(en-US) Read only-
Returns the
Node
within which theRange
ends. Range.endOffset
(en-US) Read only-
Returns a number representing where in the
endContainer
theRange
ends. Range.startContainer
(en-US) Read only-
Returns the
Node
within which theRange
starts. Range.startOffset
(en-US) Read only-
Returns a number representing where in the
startContainer
theRange
starts.
建構式
Range()
(en-US) 實驗性質-
Returns a
Range
object with the globalDocument
as its start and end.
方法
There are no inherited methods.
Range.setStart()
(en-US)-
Sets the start position of a
Range
. Range.setEnd()
(en-US)-
Sets the end position of a
Range
. Range.setStartBefore()
(en-US)-
Sets the start position of a
Range
relative to anotherNode
. Range.setStartAfter()
(en-US)-
Sets the start position of a
Range
relative to anotherNode
. Range.setEndBefore()
(en-US)-
Sets the end position of a
Range
relative to anotherNode
. Range.setEndAfter()
(en-US)-
Sets the end position of a
Range
relative to anotherNode
. Range.selectNode()
(en-US)-
Sets the
Range
to contain theNode
and its contents. Range.selectNodeContents()
(en-US)-
Sets the
Range
to contain the contents of aNode
. Range.collapse()
(en-US)-
Collapses the
Range
to one of its boundary points. Range.cloneContents()
(en-US)-
Returns a
DocumentFragment
copying the nodes of aRange
. Range.deleteContents()
(en-US)-
Removes the contents of a
Range
from theDocument
. Range.extractContents()
(en-US)-
Moves contents of a
Range
from the document tree into aDocumentFragment
. Range.insertNode()
(en-US)-
Insert a
Node
at the start of aRange
. Range.surroundContents()
(en-US)-
Moves content of a
Range
into a newNode
. Range.compareBoundaryPoints()
(en-US)-
Compares the boundary points of the
Range
with anotherRange
. Range.cloneRange()
(en-US)-
Returns a
Range
object with boundary points identical to the clonedRange
. Range.detach()
(en-US)-
Releases the
Range
from use to improve performance. Range.toString()
(en-US)-
Returns the text of the
Range
. Range.compareNode()
(en-US) 已棄用 非標準-
Returns a constant representing whether the
Node
is before, after, inside, or surrounding the range. Range.comparePoint()
(en-US) 實驗性質-
Returns -1, 0, or 1 indicating whether the point occurs before, inside, or after the
Range
. Range.createContextualFragment()
(en-US) 實驗性質-
Returns a
DocumentFragment
created from a given string of code. Range.getBoundingClientRect()
(en-US) 實驗性質-
Returns a
DOMRect
(en-US) object which bounds the entire contents of theRange
; this would be the union of all the rectangles returned byrange.getClientRects()
(en-US). Range.getClientRects()
(en-US) 實驗性質-
Returns a list of
DOMRect
(en-US) objects that aggregates the results ofElement.getClientRects()
(en-US) for all the elements in theRange
. Range.intersectsNode()
(en-US) 實驗性質-
Returns a
boolean
indicating whether the given node intersects theRange
. Range.isPointInRange()
(en-US) 實驗性質-
Returns a
boolean
indicating whether the given point is in theRange
.
規範
Specification |
---|
DOM Standard # interface-range |
DOM Parsing and Serialization # extensions-to-the-range-interface |
CSSOM View Module # extensions-to-the-range-interface |
瀏覽器相容性
BCD tables only load in the browser