Why can I prevent the Default event when I open the key, but not on the keyboard with Javascript?

When using, .keydownI can capture the keydown event, and then check and prevent the default action (display the character).

When using .keyupcan not I?

I know that an event is recorded as alert()triggered when the code is inside the condition, but preventDefault()does not prevent the action.

Here is the complete demo

+4
source share
2 answers

keyup , keydown , , , .

, , :
keydown → (keypress → ( )) , → keyup

  • keydown → → :
  • keypress → → :
  • keyup→ , :
+13

keydown() , , .

, , , keyup() .

. keyup()

, keydown keyup ( ) ( ASCII, keyCode)

0

All Articles