StaticRange

DOM StaticRange interface extends AbstractRange to provide a method to specify a range of content in the DOM whose contents don't update to reflect changes which occur within the DOM tree. It offers the same set of properties and methods as AbstractRange .

AbstractRange and StaticRange are not available from web workers .

构造函数

StaticRange()
创建新的 StaticRange object given the StaticRangeInit dictionary specifying the default values for its properties.

特性

The properties below are inherited from its parent interface, AbstractRange .

StaticRange.collapsed 只读
Returns a Boolean value which is true if the range's start and end positions are the same, resulting in a range of length 0.
StaticRange.endContainer 只读
Returns the DOM Node which contains the ending point of the range. The offset into the node at which the end position is located is indicated by endOffset .
StaticRange.endOffset 只读
Returns an integer value indicating the offset into the node given by endContainer at which the last character of the range is found.
StaticRange.startContainer 只读
Returns the DOM Node which contains the starting point of the range (which is in turn identified by startOffset .
StaticRange.startOffset 只读
Returns an integer value indicating the offset into the node specified by startContainer at which the first character of the range is located.

方法

StaticRange.toRange()
返回新 Range object which describes the same range as the source StaticRange , but is "live" with values that change to reflect changes in the contents of the DOM tree.

Usage notes

A DOM range specifies a span of content in a document, potentially beginning inside one node (or element) and ending inside another one. Unlike a Range StaticRange represents a range which is fixed in time; it does not change to try to keep the same content within it as the document changes. If any changes are made to the DOM, the actual data contained within the range specified by a StaticRange may change. This lets the user agent avoid a lot of work that is unnecessary if the web app or site doesn't need a live-updating range.

规范

规范 状态 Comment
DOM
The definition of 'StaticRange' in that specification.
实时标准
Static Range
The definition of 'StaticRange' in that specification.
编者草案 初始定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
StaticRange Chrome 60 Edge 18 Firefox 69
注意事项
69
注意事项
In Firefox, StaticRange can currently only be used by browser-internal code or code with enhanced permissions; it is not yet exposed to the web.
IE 不支持 No Opera 47 Safari 10.1 WebView Android 60 Chrome Android 60 Firefox Android 不支持 No Opera Android 44 Safari iOS 10.3 Samsung Internet Android 8.0
StaticRange() 构造函数 Chrome 不支持 No Edge 不支持 No Firefox 71 IE 不支持 No Opera 不支持 No Safari 13.1 WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 不支持 No Opera Android 不支持 No Safari iOS 13.4 Samsung Internet Android 不支持 No
collapsed Chrome 60 Edge 18 Firefox 69 IE 不支持 No Opera 47 Safari 10.1 WebView Android 60 Chrome Android 60 Firefox Android 不支持 No Opera Android 44 Safari iOS 10.3 Samsung Internet Android 8.0
endContainer Chrome 60 Edge 18 Firefox 69 IE 不支持 No Opera 47 Safari 10.1 WebView Android 60 Chrome Android 60 Firefox Android 不支持 No Opera Android 44 Safari iOS 10.3 Samsung Internet Android 8.0
endOffset Chrome 60 Edge 18 Firefox 69 IE 不支持 No Opera 47 Safari 10.1 WebView Android 60 Chrome Android 60 Firefox Android 不支持 No Opera Android 44 Safari iOS 10.3 Samsung Internet Android 8.0
startContainer Chrome 60 Edge 18 Firefox 69 IE 不支持 No Opera 47 Safari 10.1 WebView Android 60 Chrome Android 60 Firefox Android 不支持 No Opera Android 44 Safari iOS 10.3 Samsung Internet Android 8.0
startOffset Chrome 60 Edge 18 Firefox 69 IE 不支持 No Opera 47 Safari 10.1 WebView Android 60 Chrome Android 60 Firefox Android 不支持 No Opera Android 44 Safari iOS 10.3 Samsung Internet Android 8.0
toRange() Chrome 60 Edge 18 Firefox 不支持 No IE 不支持 No Opera 47 Safari 不支持 No WebView Android 60 Chrome Android 60 Firefox Android 不支持 No Opera Android 44 Safari iOS 不支持 No Samsung Internet Android 8.0

图例

完整支持
完整支持
不支持
不支持
见实现注意事项。

另请参阅

  • Live updating range of content within the DOM: Range
  • AbstractRange , the abstract interface from which all ranges are derived