Escape Eventlistener doesn't work, but when I type Enter it does?
P粉362071992
P粉362071992 2024-03-20 10:03:49
0
1
335

My "Escape" event listener doesn't work, but if I type "Enter" instead of "Escape" it works with "Enter".

This is my code:

addEventListener("keypress", function (event) {
  if (event.key === "Escape") {
    spanClick();
  }
});

P粉362071992
P粉362071992

reply all(1)
P粉523625080

The problem is that the keypress event does not detect the "Escape" key. keypress events are generally only used for character keys and not special keys. Please use the keydown or keyup event instead.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template