aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/range/collapse/index.html
blob: 621eae884f5c87d892dfa4542e3b9870052390a8 (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: Range.collapse()
slug: Web/API/Range/collapse
translation_of: Web/API/Range/collapse
---
<div>{{APIRef("DOM")}}</div>

<p><code><strong>Range.collapse()</strong></code> 方法向边界点折叠该 {{domxref("Range")}}</p>

<p>折叠后的 {{domxref("Range")}} 为空,不包含任何内容。</p>

<p>要确定 {{domxref("Range")}} 是否已折叠,使用{{domxref("Range.collapsed")}} 属性。</p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox"><em>range</em>.collapse(<em>toStart</em>);
</pre>

<h3 id="参数">参数</h3>

<dl>
 <dt><em>toStart </em>{{optional_inline}}</dt>
 <dd>一个布尔值: <code>true</code> 折叠到 {{domxref("Range")}} 的 start 节点,<code>false</code> 折叠到 end 节点。如果省略,则默认为 false {{experimental_inline}}<code>.</code></dd>
</dl>

<h2 id="例子">例子</h2>

<pre class="brush:js">var range = document.createRange();

referenceNode = document.getElementsByTagName("div").item(0);
range.selectNode(referenceNode);
range.collapse(true);
</pre>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('DOM WHATWG', '#dom-range-collapse', 'Range.collapse()')}}</td>
   <td>{{Spec2('DOM WHATWG')}}</td>
   <td>The parameter is now optional and default to <code>false</code>.</td>
  </tr>
  <tr>
   <td>{{SpecName('DOM2 Traversal_Range', 'ranges.html#Level2-Range-method-collapse', 'Range.collapse()')}}</td>
   <td>{{Spec2('DOM2 Traversal_Range')}}</td>
   <td>Initial specification.</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<div id="compat-desktop">{{Compat("api.Range.collapse")}}</div>

<h2 id="参阅">参阅</h2>

<ul>
 <li><a href="/en-US/docs/DOM/DOM_Reference">The DOM interfaces index</a></li>
</ul>