I'm not sure if this is compatible in all browsers, but I noticed that the esc button will usually reset the text entered in the text input, but only when focusing inside the text input. Or else, esc will reset the text if the onchange event has not yet occurred.
And I would suggest that you don’t need to use JavaScript to capture key events inside input and prevent default behavior.
rwalker
source share