{ }) onselect = (event) => { } 事件">

HTMLInputElement: select 事件

次元: 365bet备用地址 时间戳: 2026-02-07 00:17:57 观察者: admin 访问量: 7675 能量值: 79
HTMLInputElement: select 事件

语法

在诸如 addEventListener() 之类的方法中使用事件名称,或设置事件处理程序属性。

jsaddEventListener("select", (event) => { })

onselect = (event) => { }

事件类型

一个通用的 Event。

示例

选择记录器

html

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

onselect 等效项

您也可以使用 onselect 属性来设置事件处理程序。

jsinput.onselect = logSelection;

规范

规范

HTML# event-select

HTML# handler-onselect

浏览器兼容性

加载中…

帮助改进 MDN

此页面对您有帮助吗?

了解如何贡献 此页面最后修改于 ⁨2025年9月25日⁩,由 MDN 贡献者 修改。

在 GitHub 上查看此页面 • 报告此内容的错误

相关维度

陌陌头像怎么换

陌陌头像怎么换

奇迹3d翅膀怎么合?合翅膀方法详解

奇迹3d翅膀怎么合?合翅膀方法详解

海怡人物志丨赫克托:一人一城的科隆凡人英雄

海怡人物志丨赫克托:一人一城的科隆凡人英雄

崩坏3爱迪生怎么样 圣痕爱迪生属性技能图鉴

崩坏3爱迪生怎么样 圣痕爱迪生属性技能图鉴