Element:input 事件

示例

每当用户修改 元素的 value 时,这个示例会记录 value。

HTML

html

JavaScript

jsconst input = document.querySelector("input");

const log = document.getElementById("values");

input.addEventListener("input", updateValue);

function updateValue(e) {

log.textContent = e.target.value;

}

结果

属性

Property

Type

Description

target 只读

EventTarget

The event target (the topmost target in the DOM tree).

type 只读

String

The type of event.

bubbles 只读

Boolean

Whether the event normally bubbles or not.

cancelable 只读

Boolean

Whether the event is cancellable or not.

规范

规范

UI Events# event-type-input

HTML# handler-oninput

浏览器兼容性

参见

相关事件

beforeinput

change

invalid

帮助改进 MDN

此页面对您有帮助吗?

了解如何参与贡献

此页面最后更新于 2026年5月22日,由 MDN 贡献者更新。

在 GitHub 上查看此页面 • 报告此内容的问题