InputEvent:InputEvent() 构造函数

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

InputEvent() 构造函数创建一个新的 InputEvent 对象。

语法

js
new InputEvent(type)
new InputEvent(type, options)

参数

type

表示事件名称的字符串。区分大小写,浏览器将其设置为 beforeinput 或者 input

options 可选

一个对象,除了 UIEvent() 中定义的属性之外,还具有以下属性:

inputType 可选

指定可编辑内容更改类型的字符串,例如插入、删除或格式化文本。

data 可选

包含要插入的字符的字符串。如果更改未插入文本(例如删除字符时),则其可能为空字符串。

isComposing 可选

一个布尔值,指示事件是组合会话的一部分,这意味着它在 compositionstart 事件之后,但在 compositionend 事件之前。默认值为 false

返回值

一个 InputEvent 对象。

规范

Specification
UI Events
# dom-inputevent-inputevent

浏览器兼容性

BCD tables only load in the browser

参见

  • InputEvent,它构造的对象所属的接口。