onKeyPress Vs. onKeyUp and onKeyDown

前端 未结 12 644
醉酒成梦
醉酒成梦 2020-11-22 07:44

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

  • The onKeyDown event is triggered when the user pre
12条回答
  •  有刺的猬
    2020-11-22 08:06

    Updated Answer:

    KeyDown

    • Fires multiple times when you hold keys down.
    • Fires meta key.

    KeyPress

    • Fires multiple times when you hold keys down.
    • Does not fire meta keys.

    KeyUp

    • Fires once at the end when you release key.
    • Fires meta key.

    This is the behavior in both addEventListener and jQuery.

    https://jsbin.com/vebaholamu/1/edit?js,console,output <-- try example

    (answer has been edited with correct response, screenshot & example)

提交回复
热议问题