开发者

Make Up/Down arrow in input boxes not do anything

How can I make <input> elements not react to pressing the Up arrow (keyCode 38) or the Down arrow (keyCode 40), while they are focus开发者_StackOverflowed? I'm using jQuery for the project, but have no qualms against writing it in raw JS if that's easier.


Like this:

$('.yourinputclass').keypress(function(e) {
    if(e.which == 38 or e.which == 40) return false; // or you can use e.preventDefault(); like it was mentioned in the comments
});

Documentation here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜