When using the example code from the jQuery documentation for the keypress event handler, I'm unable to capture the Delete key. The snippet below is going to log 0
when the Delete key is pressed in FireFox:
$(document).keypress(function(e) {
console.log(e.which);
});
Seems there's gotta be a way to capture the Delete key, but it's an ambiguous term so Google isn't proving to be much help with it.
You shouldn't use the keypress
event, but the keyup
or keydown
event because the keypress
event is intended for real (printable) characters. keydown
is handled at a lower level so it will capture all nonprinting keys like delete and enter.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)