Selection.addRange()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.
概述
语法
sel.addRange(range)
参数
例子
js
/* 在一个 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);
}
规范
Specification |
---|
Selection API # dom-selection-addrange |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
addRange |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
相关链接
Selection
,此方法所属接口。