diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/selection/removerange | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/selection/removerange')
-rw-r--r-- | files/zh-cn/web/api/selection/removerange/index.html | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/selection/removerange/index.html b/files/zh-cn/web/api/selection/removerange/index.html new file mode 100644 index 0000000000..42a20eb578 --- /dev/null +++ b/files/zh-cn/web/api/selection/removerange/index.html @@ -0,0 +1,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 > 1) { + for(var i = 1; i < 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> |