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

概述

向选区(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);
}

Specifications

Specification Status Comment
HTML Editing APIs
Selection.addRange()
Editor's Draft Initial definition
Selection API
Selection.addRange()
Working Draft Current

浏览器兼容

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!
Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support ? (Yes) (Yes) ? ? ?
Feature Android Edge Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support ? (Yes) (Yes) 1.0 ? ? ?

See also

文档标签和贡献者

此页面的贡献者: Ghost_2017, rguanghui, teoli, khalid32, Losses
最后编辑者: Ghost_2017,