問題描述
好的,.keypress 和 .keydown/.keyup 有什么區別?目前我正在使用 .keydown ,它為我的鍵返回 38 的 .which 值,現在如果我將其更改為 .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
討論哪個 key 已更改.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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!