blob: 80a526f1fb2ee87aac7d1a9434d647ec1b34694e (
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
66
67
68
69
70
71
|
---
title: Selection.collapse()
slug: Web/API/Selection/collapse
tags:
- API
- HTML Editing
- Method
- Selection
translation_of: Web/API/Selection/collapse
---
<div>{{ApiRef("DOM")}}{{SeeCompatTable}}</div>
<p> <strong><code>Selection.collapse()</code></strong> 方法可以收起当前选区到一个点。文档不会发生改变。如果选区的内容是可编辑的并且焦点落在上面,则光标会在该处闪烁。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><var>sel</var>.collapse(<var>parentNode</var>, <var>offset</var>);
</pre>
<h3 id="参数">参数</h3>
<dl>
<dt><em><code>parentNode</code></em></dt>
<dd>光标落在的目标节点。</dd>
</dl>
<dl>
<dt><em><code>offset</code></em> {{optional_inline}}</dt>
<dd>落在节点的偏移量。</dd>
</dl>
<h2 id="例子">例子</h2>
<pre class="brush: js">/* 将光标收起到文档body的开头 */
var body = document.getElementsByTagName("body")[0];
window.getSelection().collapse(body,0);
</pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">规范</th>
<th scope="col">状态</th>
<th scope="col">备注</th>
</tr>
<tr>
<td>{{SpecName('Selection API', '#widl-Selection-collapse-void-Node-node-unsigned-long-offset', 'Selection.collapse()')}}</td>
<td>{{Spec2('Selection API')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('HTML Editing', '#dom-selection-collapse', 'Selection.collapse()')}}</td>
<td>{{Spec2('HTML Editing')}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<div>{{Compat("api.Selection.collapse")}}</div>
<div id="compat-mobile"> </div>
<h2 id="相关连接">相关连接</h2>
<ul>
<li>{{domxref("Selection")}}, 本方法所属的接口.</li>
</ul>
|