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粉5236250802024-03-21 09:02:12
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.