From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/selection/addrange/index.html | 68 +++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 files/zh-cn/web/api/selection/addrange/index.html (limited to 'files/zh-cn/web/api/selection/addrange') diff --git a/files/zh-cn/web/api/selection/addrange/index.html b/files/zh-cn/web/api/selection/addrange/index.html new file mode 100644 index 0000000000..3c0f54a082 --- /dev/null +++ b/files/zh-cn/web/api/selection/addrange/index.html @@ -0,0 +1,68 @@ +--- +title: Selection.addRange() +slug: Web/API/Selection/addRange +translation_of: Web/API/Selection/addRange +--- +
{{ApiRef}}
+ +

概述

+ +

向选区({{domxref("Selection")}})中添加一个区域({{domxref("Range")}})。

+ +

语法

+ +
sel.addRange(range)
+ +

参数

+ +
+
range
+
一个区域({{ domxref("Range") }})对象将被增加到选区({{ domxref("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);
+}
+ +

规范

+ + + + + + + + + + + + + + + + + + + +
规范状态注释
{{SpecName('HTML Editing', '#dom-selection-addrange', 'Selection.addRange()')}}{{Spec2('HTML Editing')}}Initial definition
{{SpecName('Selection API', '#widl-Selection-addRange-void-Range-range', 'Selection.addRange()')}}{{Spec2('Selection API')}}Current
+ +

浏览器兼容性

+ +

{{Compat("api.Selection.addRange")}}

+ +

相关链接

+ + -- cgit v1.2.3-54-g00ecf