aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/selection/removerange/index.html
blob: 42a20eb578148ff44eda9cf23a10deda9c7d63f3 (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
---
title: Selection.removeRange()
slug: Web/API/Selection/removeRange
translation_of: Web/API/Selection/removeRange
---
<p>{{ ApiRef() }}</p>
<h3 id="Summary" name="Summary">概述</h3>
<p>将一个区域从选区中移除。</p>
<h3 id="Syntax" name="Syntax">用法</h3>
<pre class="eval"><i>sel</i>.removeRange(<i>range</i>)
</pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<dl>
 <dt>
  <i>
   <code>range</code></i>
 </dt>
 <dd>
  Range对象将从选区当中移除。</dd>
</dl>
<h3 id="Examples" name="Examples">Examples</h3>
<pre class="eval">/* 通过设计一段js代码,我们可以获得多个区域,
 * 这段代码可以移除除了第一个<span style="font-size: 1rem;">区域</span><span style="font-size: 1rem;">之外的所有</span><span style="font-size: 1rem;">区域</span><span style="font-size: 1rem;"></span><span style="font-size: 1rem;"> * (此代码在Chrome中不生效,因为Chrome当中只能
 * 选择一个选区,哎我为什么要在 Mozilla 的网站上
 * 说这个?译者注)*/</span>

s = window.getSelection();
if(s.rangeCount &gt; 1) {
 for(var i = 1; i &lt; s.rangeCount; i++) {
  s.removeRange(s.getRangeAt(i));
 }
}
</pre>
<div class="noinclude">
  </div>
<p>{{ languages( { "es": "es/DOM/Selection/removeRange", "it": "it/DOM/Selection/removeRange", "pl": "pl/DOM/Selection/removeRange" } ) }}</p>