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

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

问题描述

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

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


当用户按下一个Key
时,会触发 KeyDown 事件。


用户释放密钥时会触发 KeyUp 事件。

用户按下&bbsp;
时会触发 KeyPress 事件发布密钥。
(onKeyDown后跟onKeyUp)

The KeyPress event is triggered when the user presses & releases a Key. (onKeyDown followed by onKeyUp)

我理解前两个,但不是 KeyPress KeyUp 相同? (或者可以在没有按下( KeyDown )的情况下释放一个键( KeyUp )吗?)

I understand the first two, but isn't KeyPress the same as KeyUp? (or is it possible to release a key(KeyUp) without pressing(KeyDown) it?)

这个有点混乱,有人可以为我清除这个吗?

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

推荐答案

点击这里查看存档的最初在此答案中使用的链接

从该链接:


理论上,keydown和keyup
事件代表被按下的键或
被释放,而keypress事件
代表被键入的字符。
理论的实现是
在所有浏览器中都不一样。

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

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

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