aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/element/select_event
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/element/select_event
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/element/select_event')
-rw-r--r--files/zh-cn/web/api/element/select_event/index.html132
1 files changed, 132 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/element/select_event/index.html b/files/zh-cn/web/api/element/select_event/index.html
new file mode 100644
index 0000000000..bd9f49413a
--- /dev/null
+++ b/files/zh-cn/web/api/element/select_event/index.html
@@ -0,0 +1,132 @@
+---
+title: select
+slug: Web/API/Element/select_event
+tags:
+ - Event
+translation_of: Web/API/Element/select_event
+---
+<div>{{APIRef}}</div>
+
+<p><strong><code>select</code></strong> 选择某些文本时会触发事件。</p>
+
+<p>该事件不适用于所有语言的所有元素。例如,在 HTML,<code>select</code>事件只能在表单{{HtmlElement('input/text', '&lt;input type="text"&gt;')}}和 {{HtmlElement("textarea")}}元素上触发。</p>
+
+<h2 id="General_info">General info</h2>
+
+<table class="properties">
+ <thead>
+ </thead>
+ <tbody>
+ <tr>
+ <th>Interface</th>
+ <td>{{domxref("UIEvent")}} if generated from a user interface, {{domxref("Event")}} otherwise</td>
+ </tr>
+ <tr>
+ <th>Bubbles</th>
+ <td>Yes</td>
+ </tr>
+ <tr>
+ <th>Cancelable</th>
+ <td>No</td>
+ </tr>
+ <tr>
+ <th>Target</th>
+ <td>{{domxref("Element")}}</td>
+ </tr>
+ <tr>
+ <th>Default Action</th>
+ <td>None</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="属性">属性</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Property</th>
+ <th scope="col">Type</th>
+ <th scope="col">Description</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><code>target</code> {{readonlyInline}}</td>
+ <td><a href="/en-US/docs/Web/API/EventTarget" title="EventTarget is an interface implemented by objects that can receive events and may have listeners for them."><code>EventTarget</code></a></td>
+ <td>The event target (the topmost target in the DOM tree).</td>
+ </tr>
+ <tr>
+ <td><code>type</code> {{readonlyInline}}</td>
+ <td><a href="/en-US/docs/Web/API/DOMString" title="DOMString is a UTF-16 String. As JavaScript already uses such strings, DOMString is mapped directly to a String."><code>DOMString</code></a></td>
+ <td>The type of event.</td>
+ </tr>
+ <tr>
+ <td><code>bubbles</code> {{readonlyInline}}</td>
+ <td><a href="/en-US/docs/Web/API/Boolean" title="The Boolean object is an object wrapper for a boolean value."><code>Boolean</code></a></td>
+ <td>Whether the event normally bubbles or not.</td>
+ </tr>
+ <tr>
+ <td><code>cancelable</code> {{readonlyInline}}</td>
+ <td><a href="/en-US/docs/Web/API/Boolean" title="The Boolean object is an object wrapper for a boolean value."><code>Boolean</code></a></td>
+ <td>Whether the event is cancellable or not.</td>
+ </tr>
+ <tr>
+ <td><code>view</code> {{readonlyInline}}</td>
+ <td><a class="new" href="/en-US/docs/Web/API/WindowProxy" rel="nofollow" title="The documentation about this has not yet been written; please consider contributing!"><code>WindowProxy</code></a></td>
+ <td><a href="/en-US/docs/Web/API/Document/defaultView" title="In browsers, document.defaultView returns the window object associated with a document, or null if none is available."><code>document.defaultView</code></a> (<code>window</code> of the document)</td>
+ </tr>
+ <tr>
+ <td><code>detail</code> {{readonlyInline}}</td>
+ <td><code>long</code> (<code>float</code>)</td>
+ <td>0.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="示例">示例</h2>
+
+<h3 id="HTML">HTML</h3>
+
+<pre class="brush: html">&lt;input value="Try selecting some text in this element."&gt;
+&lt;p id="log"&gt;&lt;/p&gt;</pre>
+
+<h3 id="JavaScript">JavaScript</h3>
+
+<pre class="brush: js">function logSelection(event) {
+ const log = document.getElementById('log');
+ const selection = event.target.value.substring(event.target.selectionStart, event.target.selectionEnd);
+ log.textContent = `You selected: ${selection}`;
+}
+
+const input = document.querySelector('input');
+input.addEventListener('select', logSelection);</pre>
+
+<h3 id="结果">结果</h3>
+
+<p>{{EmbedLiveSample("示例")}}</p>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('UI Events', '#event-type-select', 'select')}}</td>
+ <td>{{Spec2('UI Events')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="参见">参见</h2>
+
+<ul>
+ <li>{{domxref("GlobalEventHandlers.onselect")}}</li>
+</ul>