此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

键盘事件 KeyboardEvent()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

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

语法

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

typeArg

DOMString 类型,表示事件名称。

KeyboardEventInit可选

KeyboardEventInit 字典,有以下几种值:

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

规范

Specification
UI Events
# dom-keyboardevent-keyboardevent

浏览器兼容性

参考