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

概述

向选区(Selection)中添加一个区域(Range)。

语法

sel.addRange(range)

参数

range
一个区域(Range)对象将被增加到选区(Selection)当中。

例子

/* 在一个HTML文档中选中所有加粗的文本。 */

var strongs = document.getElementsByTagName("strong");
var s = window.getSelection();

if(s.rangeCount > 0) s.removeAllRanges();

for(var i = 0; i < strongs.length; i++) {
  var range = document.createRange();
  range.selectNode(strongs[i]);
  s.addRange(range);
}

规范

规范 状态 注释
HTML Editing APIs
Selection.addRange()
Editor's Draft Initial definition
Selection API
Selection.addRange()
Working Draft Current

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
addRange
Experimental
Chrome Full support 1Edge Full support 12Firefox Full support YesIE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile 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.

相关链接

文档标签和贡献者

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