aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/selection/rangecount
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/api/selection/rangecount')
-rw-r--r--files/zh-cn/web/api/selection/rangecount/index.html129
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。
+
+&lt;table&gt;
+&lt;tr&gt;&lt;td&gt;a.1&lt;td&gt;a.2
+&lt;tr&gt;&lt;td&gt;b.1&lt;td&gt;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>