can't fire keypress event when press delete key

后端 未结 2 899
迷失自我
迷失自我 2021-02-12 19:28

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

2条回答
  •  余生分开走
    2021-02-12 20:09

    Use 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);
    

提交回复
热议问题