Why does the start of keydown start, but keyup is not?

$(document).on('keydown', function(e) { if (e.shiftKey) { $('body').append('test1'); } }); $(document).on('keyup', function(e) { if (e.shiftKey) { $('body').append('test'); } }); 

keyup never starts for me, but keydown does, why?

+6
source share
2 answers

event.shiftKey always return false on the keyboard.

Check instead of keyCode === 16 (this is a shift of key code, on the keyboard):

 $(document).on('keydown', function(e) { if (e.shiftKey) { $('body').append('test1'); } }).on('keyup', function(e) { if (e.keyCode === 16) { $('body').append('test'); } }); 

Demo: http://jsfiddle.net/maniator/eyX5N/

+4
source

e.shiftKey always return false when used in the keyUp event ... Your event fires, the test simply fails.

+2
source

Source: https://habr.com/ru/post/957936/


All Articles