Chrome 10:KeyEvent 或类似于 Firefox 的 KeyEvent 的东西
在 Firefox 3.6 和 4.0 中,我可以将 KeyboardEvent
的 keyCode
与存储在全局 KeyEvent
对象(这是 DOM3 规范的一部分)。 KeyEvent
不是 Chrome 10.0 中的全局对象。有没有办法可以在 Chrome 10.0 中访问具有预定义键常量的对象?这甚至实施了吗?
示例:
// This works in firefox 3/4.
// How do I do this in chrome?
if (event.keyCode === KeyEvent.DOM_VK_RETURN) {
// Do stuff...
} else if (event.keyCode === KeyEvent.DOM_VK_ESCAPE) {
// Do something else.
}
是的,我知道 Enter/Return 键代码是 13,Escape 键代码是 27。
In Firefox 3.6 and 4.0 I can compare a KeyboardEvent
's keyCode
against predefined constants for keys stored inside of the global KeyEvent
object (which is part of he DOM3 specification). KeyEvent
is not a global object in Chrome 10.0. Is there a way I can access an object with predefined key constants in Chrome 10.0? Is that even implemented?
Example:
// This works in firefox 3/4.
// How do I do this in chrome?
if (event.keyCode === KeyEvent.DOM_VK_RETURN) {
// Do stuff...
} else if (event.keyCode === KeyEvent.DOM_VK_ESCAPE) {
// Do something else.
}
And yes, I am aware that the enter/return key code is 13 and escape key code is 27.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,Chrome 本身并没有携带此功能,但您可以以其他方式定义它:
Chrome doesn't carry this natively as far as I know, but you can define it otherwise: