Movatterモバイル変換


[0]ホーム

URL:


  1. 面向开发者的 Web 技术
  2. Web API
  3. HTMLInputElement
  4. select

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in EnglishAlways switch to English

select

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

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

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

General info

InterfaceUIEvent if generated from a user interface,Event otherwise
BubblesYes
CancelableNo
TargetElement
Default ActionNone

属性

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

示例

HTML

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

JavaScript

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

结果

规范

Specification
HTML
# event-select
HTML
# handler-onselect

参见

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp