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/rangecount | |
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/rangecount')
-rw-r--r-- | files/zh-cn/web/api/selection/rangecount/index.html | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/selection/rangecount/index.html b/files/zh-cn/web/api/selection/rangecount/index.html new file mode 100644 index 0000000000..ad05478e8d --- /dev/null +++ b/files/zh-cn/web/api/selection/rangecount/index.html @@ -0,0 +1,129 @@ +--- +title: Selection.rangeCount +slug: Web/API/Selection/rangeCount +tags: + - API + - Selection +translation_of: Web/API/Selection/rangeCount +--- +<div> +<div> +<div>{{ ApiRef("DOM") }}{{SeeCompatTable}}</div> +</div> +</div> + +<p>The <strong><code>Selection.rangeCount</code></strong>是一个返回选区(selection)中range对象数量的只读属性。</p> + +<p>在网页使用者点击一个加载完毕的新打开的页面之前,<strong>rangeCount</strong><font face="Consolas, Liberation Mono, Courier, monospace">的值是0</font>。在使用者点击页面之后,<font face="Consolas, Liberation Mono, Courier, monospace">rangeCount的值变为1,即使并没有可视的选区(selection)。</font></p> + +<p>使用者一般情况下在一次只能选择一个range ,所以通常情况下<strong>rangeCount属性</strong>的值总为1。脚本(如javascript)可以使选区包含多个range。</p> + +<p>Gecko 浏览器允许跨表格单元格获得多个选区(此处可能翻译不准). Firefox allows to select multiple ranges in the document by using Ctrl+click (unless the click within an element with display: table-cell).</p> + +<h2 id="Syntax" name="Syntax">用法</h2> + +<pre class="syntaxbox"><em>value</em> =<em> sel</em>.rangeCount +</pre> + +<h2 id="例子">例子</h2> + +<p>下面这个例子会每隔一秒显示一次rangeCount的值。在浏览器中选择文本,然后看看他的改变。</p> + +<h3 id="HTML_Content">HTML Content</h3> + +<pre class="brush: html">//打开控制台看看selection中有多少range对象。 +//在Gecko浏览器,当你用鼠标在表格单元格中拖动的同时按住Ctrl,你可以选择多个range。 + +<table> +<tr><td>a.1<td>a.2 +<tr><td>b.1<td>b.2 + + +</pre> + +<h3 id="JavaScript_Content">JavaScript Content</h3> + +<pre class="brush: js">window.setInterval(function () { + console.log(window.getSelection().rangeCount); +}, 1000); +</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('HTML Editing', '#dom-selection-rangecount', 'Selection.rangeCount')}}</td> + <td>{{Spec2('HTML Editing')}}</td> + <td>Initial definition</td> + </tr> + <tr> + <td>{{SpecName('Selection API', '#widl-Selection-rangeCount', 'Selection.rangeCount')}}</td> + <td>{{Spec2('Selection API')}}</td> + <td>Current</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatVersionUnknown()}}</td> + <td>{{CompatVersionUnknown()}}</td> + <td>{{CompatVersionUnknown()}}</td> + <td>{{CompatVersionUnknown()}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown()}}</td> + <td>1.0</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="See_also" name="See_also">See also</h2> + +<ul> + <li>{{domxref("Selection")}}, the interface it belongs to.</li> +</ul> |