这篇翻译不完整。请帮忙从英语翻译这篇文章

概述

返回一个包含当前选区内容的区域对象。

语法

range = sel.getRangeAt(index)

参数

range
 将返回 range 对象。
index
该参数指定需要被处理的子集编号(从零开始计数)。如果该数值被错误的赋予了大于或等于 rangeCount 结果的数字,将会产生错误。

例子

let ranges = [];

sel = window.getSelection();

for(var i = 0; i < sel.rangeCount; i++) {
 ranges[i] = sel.getRangeAt(i);
}
/* 在 ranges 数组的每一个元素都是一个 range 对象,
 * 对象的内容是当前选区中的一个。 */

规范

规范 状态 注释
HTML Editing APIs
Selection.getRangeAt()
Editor's Draft Initial definition

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
getRangeAt
Experimental
Chrome Full support YesEdge Full support 12Firefox Full support YesIE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.

相关链接

  • Tree Selection (for the getRangeAt() method on the nsITreeSelection interface)

文档标签和贡献者

此页面的贡献者: SphinxKnight, 1v9, mdnwebdocs-bot, teoli, arunpandianp, Losses
最后编辑者: SphinxKnight,