gpt4 book ai didi

events - 如何获取删除键的 event.keyCode?

转载 作者:行者123 更新时间:2023-12-04 04:48:54 28 4
gpt4 key购买 nike

$('body').keypress(function(event){

if(event.keyCode == 46){console.log('Delete Key Pressed')}; //does not work

if(event.keyCode == 32){console.log('SPACE BAR')}; //works
})

Why doesn't the delete key show up in THIS FIDDLE ?

最佳答案

使用 keyup 或 keydown 事件代替 keypress:keypress 用于可打印字符,而 keydown 将捕获非打印按键,包括删除、退格和返回。
http://jsfiddle.net/5cNTn/9/

$('body').keydown(function(event){
var letter = String.fromCharCode(event.which);
if(event.keyCode == 32){console.log('SPACE BAR');}
if(event.keyCode == 46){console.log('Delete Key Pressed');}
console.log(event);
console.log(event.keyCode);
});

关于events - 如何获取删除键的 event.keyCode?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21248641/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com