Stop keypress event

前端 未结 6 681
情歌与酒
情歌与酒 2020-12-29 19:19

How to stop keypress event in keydown.

I have a keydown handler in that I need to stop keypress event.

Ac

6条回答
  •  抹茶落季
    2020-12-29 20:04

    Here I stopped the event bubbling for up/dn/left/right keys:

        $(document).on("keydown", function(e) {
            if(e.keyCode >= 37 && e.keyCode <= 40) {
                e.stopImmediatePropagation();
                return;
            }
        });
    

    I also tried e.preventDefault or event.cancelBubble = true from the answers above, but they had no impact.

提交回复
热议问题