select
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
General info
属性
Property | Type | Description |
---|---|---|
target 只读 |
EventTarget |
The event target (the topmost target in the DOM tree). |
type 只读 |
DOMString |
The type of event. |
bubbles 只读 |
Boolean |
Whether the event normally bubbles or not. |
cancelable 只读 |
Boolean |
Whether the event is cancellable or not. |
view 只读 |
WindowProxy |
document.defaultView (window of the document) |
detail 只读 |
long (float ) |
0. |
示例
HTML
html
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 |