How to stop cursor from jumping to beginning/end of textbox on up/down key?
How can I prevent th开发者_如何学Pythone cursor from jumping to the beginning or end of a textbox when up or down arrow key is pressed, using JavaScript and jQuery?
<input type="text" />
$("input:text").keydown(function(e){
if(e.which == 38 || e.which == 40)
e.preventDefault();
});
You can prevent default on the up and down arrow keys.
http://jsfiddle.net/C5ZCE/
精彩评论