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
精彩评论