onKeyPress 对比onKeyUp 和 onKeyDown [英] onKeyPress Vs. onKeyUp and onKeyDown

查看:17
本文介绍了onKeyPress 对比onKeyUp 和 onKeyDown的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这三个事件有什么区别?谷歌搜索后我发现:

What is the difference between these three events? Upon googling I found that:

  • onKeyDown 事件在用户按下某个键时触发.
  • onKeyUp 事件在用户松开按键时触发.
  • onKeyPress 事件在用户按下 & 键时触发.释放钥匙(onKeyDown 后跟 onKeyUp).
  • The onKeyDown event is triggered when the user presses a key.
  • The onKeyUp event is triggered when the user releases a key.
  • The onKeyPress event is triggered when the user presses & releases a key (onKeyDown followed by onKeyUp).

我理解前两个,但 onKeyPressonKeyUp 不一样吗?是否可以在不按下键 (onKeyDown) 的情况下释放键 (onKeyUp)?

I understand the first two, but isn't onKeyPress the same as onKeyUp? Is it possible to release a key (onKeyUp) without pressing it (onKeyDown)?

这有点令人困惑,有人可以帮我解决这个问题吗?

This is a bit confusing, can someone clear this up for me?

推荐答案

在此处查看存档的 link 最初用于此答案.

Check here for the archived link originally used in this answer.

来自该链接:

理论上,onKeyDownonKeyUp 事件代表按键被按下或释放,而 onKeyPress 事件代表正在输入的字符.该理论在所有浏览器中的实现并不相同.

In theory, the onKeyDown and onKeyUp events represent keys being pressed or released, while the onKeyPress event represents a character being typed. The implementation of the theory is not same in all browsers.

这篇关于onKeyPress 对比onKeyUp 和 onKeyDown的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆