I can successfully stop all keys from being pressed with:
$this.keydown(false);
How can I disable all keys with the exception of the backspace key?
Check the keyCode
of the event argument:
$this.keydown(function(e) {
if(e.keyCode !== 8) {
e.preventDefault();
}
});
Here's a demo.
Use a callback, check the keycode of the pressed key, if it's the backspace key then allow it, otherwise block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With