preventDefault() on keyup event not working

前端 未结 4 1017
不思量自难忘°
不思量自难忘° 2021-02-19 06:20

I cannot get preventDefault() to work.

Here are some different code variations I have tried:

First:

$(document).keyup(function (evt)         


        
4条回答
  •  灰色年华
    2021-02-19 07:02

    You are using JQuery, which normalises the differences between browsers, so you only need to to check the evt.which property. See the JQuery documentation: http://api.jquery.com/keyup/

    As others have said - keyup is too late to stop the processing of the key. Use keydown or keypress instead. http://api.jquery.com/category/events/keyboard-events/

提交回复
热议问题