admin管理员组文章数量:1180473
I'm finding that the delete key doesn't fire the keypress
event in Chrome, while other keys work. The problem doesn't occur in Firefox, just in Chrome, why? Here is my code:
document.addEventListener('keypress', function (e) {
console.log(e);
}, false);
I'm finding that the delete key doesn't fire the keypress
event in Chrome, while other keys work. The problem doesn't occur in Firefox, just in Chrome, why? Here is my code:
document.addEventListener('keypress', function (e) {
console.log(e);
}, false);
Share
Improve this question
edited Jun 20, 2021 at 10:21
Brian Tompsett - 汤莱恩
5,87372 gold badges61 silver badges133 bronze badges
asked Apr 17, 2012 at 8:06
qiu8310qiu8310
2371 gold badge2 silver badges8 bronze badges
2 Answers
Reset to default 26Use keydown
or keyup
instead, it captures the delete key (as well as others that keypress doesn't, see http://www.quirksmode.org/js/keys.html)
document.addEventListener('keydown', function (e) {
console.log(e);
}, false);
keypress
event for (Del, End, Home,etc..) is not fired in IE, Chrome and safari.. it only works in firefox..
so you can use the keyup
or keydown
event because the keypress
event is intented for real (printable) characters. "keydown"
is handled at a lower level so it will capture all non-printing keys like DEL, End, etc
本文标签: javascriptCan39t fire keypress event when press delete keyStack Overflow
版权声明:本文标题:javascript - Can't fire keypress event when press delete key - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738176476a2067277.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论