blob: bd9f49413a852d65de93afe636a885d127adf747 (
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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', '<input type="text">')}}和 {{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"><input value="Try selecting some text in this element.">
<p id="log"></p></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>
|