preventDefault() on keyup event not working

前端 未结 4 1021
不思量自难忘°
不思量自难忘° 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 06:45

    see working example here http://jsfiddle.net/WGSvm/

    In all three examples you have used

    $(document).keyup(function (evt) {  });
    

    I would say use particular div id instead of $(document).keyup(function (evt) { });

    like $("#DivIdName").keyup(function (evt) { }); and also use onkeypress strictly, because if you use onkeyup it has already executed its default task of printing or whatever it is.

提交回复
热议问题