键盘事件 KeyboardEvent()

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.

KeyboardEvent() 构造函数新建一个 KeyboardEvent 实例。

语法

js
new KeyboardEvent(type)
new KeyboardEvent(type, options)

typeArg

DOMString 类型,表示事件名称。

KeyboardEventInit可选

KeyboardEventInit 字典,有以下几种值:

备注: KeyboardEventInit 字典也可以接受来自 UIEventInitEventInit 的字典字段值。

规范

Specification
UI Events
# dom-keyboardevent-keyboardevent

浏览器兼容性

BCD tables only load in the browser

参考