javascript - Cancel the keydown in HTML -
How can I cancel the keydown
of a specific key on the keyboard, for example ( Enter the space in an HTML page and arrow
).
If you are interested only in the example tricks you mentioned, keydown
event Except the old, pre-opted versions of Opera (except for version 12, and at least with), where you have to cancel the keypress
event keypress
In the keydown
event, it is very easy to reliably identify non-printable keys, so the following Uses a variable to set in keydown
in order to tell the handler to questions
handler to see if the default behavior is suppressed or not.
var cancellationpress = wrong; Document.onkeydown = function (evt) {evt = evt || Window.event; Canceled Keypress = / ^ (13 | 32 | 37 | 38 | 39 | 40) $ / trial ("+ + + evt.keyCode); if (cancel the KApr) {return false;}}; / * Opera * / Document.onkeypress = function (evt) {if (cancel kaypress) {return false;}};
Comments
Post a Comment