jQuery .keypress& .keydown .which [英] jQuery .keypress & .keydown .which

查看:90
本文介绍了jQuery .keypress& .keydown .which的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那么.keypress和.keydown / .keyup的区别是什么?目前我正在使用.keydown,它为我的密钥返回.which值为38,现在如果我将其更改为.keypress,它会为该相同的密钥返回值109。有什么区别,为什么同一个键的值不同?

Ok so what is the difference in .keypress and .keydown/.keyup? At present I am using .keydown which returns a .which value of 38 for my key, now if i change it to .keypress it returns a value of 109 for that same key. What is the difference and why are the values different for the same key?

推荐答案

如果按一个按钮就会触发 keydown 并释放它会触发 keyup keypress 通常介于这两者之间。

If you press a button it fires a keydown and releasing it fires a keyup. The keypress usually comes between those two.

keydown keyup 说说 已更改。 keypress 告诉该键代表哪个 字符

keydown and keyup talk about which key has been changed. keypress tells which character that key represents.

请注意,这完全取决于浏览器!

Note that this is all browser-dependent!

参见这篇文章介绍了在各种浏览器上实现的关键事件之间的差异

这篇关于jQuery .keypress& .keydown .which的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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