keypress - Web API 接口参考 编辑

The keypress event is fired when a key is pressed down and that key normally produces a character value (use input instead).

General info

Specification
DOM L3
Interface
KeyboardEvent
Bubbles
Yes
Cancelable
Yes
Target
Document, Element
Default Action
Varies: keypress event; launch text composition system; blur and focus events; DOMActivate event; other event

Properties

PropertyTypeDescription
target 只读EventTargetThe event target (the topmost target in the DOM tree).
type 只读DOMStringThe type of event.
bubbles 只读BooleanWhether the event normally bubbles or not
cancelable 只读BooleanWhether the event is cancellable or not?
view 只读WindowProxydocument.defaultView (window of the document)
detail 只读long (float)0.
target 只读EventTarget (DOM element)Focused element processing the key event, root element if no suitable input element focused.
char 只读DOMString (string)The character value of the key. If the key corresponds to a printable character, this value is a non-empty Unicode string containing that character. If the key doesn't have a printable representation, this is an empty string. See key names and char values for the detail. Note: If the key is used as a macro that inserts multiple characters, this attribute's value is the entire string, not just the first character.
key 只读DOMString (string)The key value of the key represented by the event. If the value has a printed representation, this attribute's value is the same as the char attribute. Otherwise, it's one of the key value strings specified in Key values. If the key can't be identified, this is the string "Unidentified". See key names and char values for the detail. Read Only.
charCode 只读Unsigned long (int)The Unicode reference number of the key; this attribute is used only by the keypress event. For keys whose char attribute contains multiple characters, this is the Unicode value of the first character in that attribute. Warning: This attribute is deprecated; you should use char instead, if available.
keyCode 只读Unsigned long (int)A system and implementation dependent numerical code identifying the unmodified value of the pressed key. This is usually the decimal ASCII (RFC 20) or Windows 1252 code corresponding to the key; see Virtual key codes for a list of common values. If the key can't be identified, this value is 0. Warning: This attribute is deprecated; you should use key instead, if available.
which 只读Unsigned long (int)A system and implementation dependent numeric code identifying the unmodified value of the pressed key; this is usually the same as keyCode. Warning: This attribute is deprecated; you should use key instead, if available.
location 只读long (float)The location of the key on the device.
repeat 只读booleantrue if a key has been depressed long enough to trigger key repetition, otherwise false.
locale 只读stringThe language code for the key event, if available; otherwise, the empty string.
ctrlKey 只读booleantrue if the control key was down when the event was fired. false otherwise.
shiftKey 只读booleantrue if the shift key was down when the event was fired. false otherwise.
altKey 只读booleantrue if the alt key was down when the event was fired. false otherwise.
metaKey 只读booleantrue if the meta key was down when the event was fired. false otherwise.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:144 次

字数:7152

最后编辑:6年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文