Cancel the keydown in HTML

后端 未结 6 935
清歌不尽
清歌不尽 2020-11-29 10:28

How can I cancel the keydown of a specific key on the keyboard, for example(space, enter and arrows) in an HTML page.

6条回答
  •  余生分开走
    2020-11-29 10:47

    This is certainly very old thread. In order to do the magic with IE10 and FireFox 29.0.1 you definitely must do this inside of keypress (not keydown) event listener function:

    if (e.preventDefault) e.preventDefault();
    

提交回复
热议问题