From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../zh-cn/web/api/element/select_event/index.html | 132 +++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 files/zh-cn/web/api/element/select_event/index.html (limited to 'files/zh-cn/web/api/element/select_event') 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 +--- +
{{APIRef}}
+ +

select 选择某些文本时会触发事件。

+ +

该事件不适用于所有语言的所有元素。例如,在 HTML,select事件只能在表单{{HtmlElement('input/text', '<input type="text">')}}和 {{HtmlElement("textarea")}}元素上触发。

+ +

General info

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Interface{{domxref("UIEvent")}} if generated from a user interface, {{domxref("Event")}} otherwise
BubblesYes
CancelableNo
Target{{domxref("Element")}}
Default ActionNone
+ +

属性

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PropertyTypeDescription
target {{readonlyInline}}EventTargetThe event target (the topmost target in the DOM tree).
type {{readonlyInline}}DOMStringThe type of event.
bubbles {{readonlyInline}}BooleanWhether the event normally bubbles or not.
cancelable {{readonlyInline}}BooleanWhether the event is cancellable or not.
view {{readonlyInline}}WindowProxydocument.defaultView (window of the document)
detail {{readonlyInline}}long (float)0.
+ +

示例

+ +

HTML

+ +
<input value="Try selecting some text in this element.">
+<p id="log"></p>
+ +

JavaScript

+ +
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);
+ +

结果

+ +

{{EmbedLiveSample("示例")}}

+ +

规范

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('UI Events', '#event-type-select', 'select')}}{{Spec2('UI Events')}} 
+ +

参见

+ + -- cgit v1.2.3-54-g00ecf