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

View in English Always switch to English

键盘事件 KeyboardEvent()

基线 广泛可用

自 2015年7月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

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

语法

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

typeArg

DOMString 类型,表示事件名称。

KeyboardEventInit可选

KeyboardEventInit 字典,有以下几种值:

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

规范

规范
UI Events
# dom-keyboardevent-keyboardevent

浏览器兼容性

参考