blob: 02716336858d9c5a25d7030c92abca238df5e6a0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
---
title: Selection.getRangeAt()
slug: Web/API/Selection/getRangeAt
translation_of: Web/API/Selection/getRangeAt
---
<div>{{APIRef}}</div>
<div><strong>概述</strong></div>
<p>返回一个包含当前选区内容的区域对象。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><em>range</em> = <em>sel</em>.getRangeAt(<em>index</em>)
</pre>
<h3 id="参数">参数</h3>
<dl>
<dt><em><code>range</code></em></dt>
<dd> 将返回 <a href="/en-US/docs/DOM/range" title="DOM/range">range</a> 对象。</dd>
<dt><em><code>index</code></em></dt>
<dd>该参数指定需要被处理的子集编号(从零开始计数)。如果该数值被错误的赋予了大于或等于 <a href="/en-US/docs/DOM/Selection/rangeCount" title="DOM/Selection/rangeCount">rangeCount</a> 结果的数字,将会产生错误。</dd>
</dl>
<h2 id="例子">例子</h2>
<pre class="brush:js">let ranges = [];
sel = window.getSelection();
for(var i = 0; i < sel.rangeCount; i++) {
ranges[i] = sel.getRangeAt(i);
}
/* 在 ranges 数组的每一个元素都是一个 range 对象,
<span> * 对象的内容是当前选区中的一个。 */</span></pre>
<h2 id="规范">规范</h2>
<table>
<tbody>
<tr>
<th scope="col">规范</th>
<th scope="col">状态</th>
<th scope="col">注释</th>
</tr>
<tr>
<td>{{SpecName('HTML Editing', '#dom-selection-getrangeat', 'Selection.getRangeAt()')}}</td>
<td>{{Spec2('HTML Editing')}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>{{Compat("api.Selection.getRangeAt")}}</p>
<h2 id="相关链接">相关链接</h2>
<ul>
<li><a href="/en-US/docs/XUL_Tutorial/Tree_Selection" title="XUL_Tutorial/Tree_Selection">Tree Selection</a> (for the <code>getRangeAt()</code> method on the <code>nsITreeSelection</code> interface)</li>
</ul>
|