非标
此特征是非标准的,且不在标准轨道中。不要在面向 Web 的生产站点中使用它:它不适用于每个用户。实现之间可能存在大的不兼容性,且行为将来可能改变。

弃用
This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the 兼容性表格 at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

KeyboardEvent.initKeyEvent() method is used to initialize the value of an event created using document.createEvent ("KeyboardEvent") . Events initialized in this way must have been created with the document.createEvent ("KeyboardEvent") 方法。 initKeyEvent() must be called to set the event before it is dispatched .

Do not use this method anymore, use the KeyboardEvent() constructor instead.

This method is based on early drafts of DOM (文档对象模型) 2 级事件规范 and is implemented in Gecko-based browsers; other browsers implemented KeyboardEvent.initKeyboardEvent based on early drafts of DOM (文档对象模型) 3 级事件规范 . Favor the modern constructor structure as the only cross-browser way of building events.

句法

event.initKeyEvent (type, bubbles, cancelable, viewArg,
                    ctrlKeyArg, altKeyArg, shiftKeyArg, metaKeyArg,
                    keyCodeArg, charCodeArg)
					

参数

type
DOMString representing the type of event.
bubbles
布尔 indicating whether the event should bubble up through the event chain or not (see bubbles ).
cancelable
布尔 i indicating whether the event can be canceled (see cancelable ).
viewArg
Specifies the UIEvent.view ; this value may be null .
ctrlKeyArg
布尔 也就是 true if the virtual key to be generated is a combination of keys containing the Ctrl key.
altKeyArg
布尔 也就是 true if the virtual key to be generated is a combination of keys containing the Alt key.
shiftKeyArg
A 布尔 也就是 true if the virtual key to be generated is a combination of keys containing the Shift key.
metaKeyArg
布尔 也就是 true if the virtual key to be generated is a combination of keys containing the Meta key.
keyCodeArg
unsigned long representing the virtual key code value of the key which was depressed, otherwise 0 。见 KeyboardEvent.keyCode for the list of key codes.
charCodeArg
unsigned long representingthe Unicode character associated with the depressed key otherwise 0 .

范例

var event = document.createEvent('KeyboardEvent'); // create a key event
// define the event
event.initKeyEvent("keypress",       // typeArg,
                   true,             // canBubbleArg,
                   true,             // cancelableArg,
                   null,             // viewArg,  Specifies UIEvent.view. This value may be null.
                   false,            // ctrlKeyArg,
                   false,            // altKeyArg,
                   false,            // shiftKeyArg,
                   false,            // metaKeyArg,
                    9,               // keyCodeArg,
                    0);              // charCodeArg);
document.getElementById('blah').dispatchEvent(event);
					

规范

This implementation of keyboard events is based on the key events spec in the early versions of DOM 2 Events , later removed from that spec.

initKeyEvent is the current Gecko equivalent of the DOM Level 3 Events (initially drafted and also deprecated in favor of KeyboardEvent() Keyboard.initKeyboardEvent() method with the following arguments :

typeArg of type DOMString
canBubbleArg of type boolean
cancelableArg of type boolean
viewArg of type views::AbstractView
keyIdentifierArg of type DOMString
keyLocationArg of type unsigned long
modifiersList of type DOMString);
					

元数据

  • 最后修改: