开发者

How to stop cursor from jumping to beginning/end of textbox on up/down key?

开发者 https://www.devze.com 2023-04-06 02:39 出处:网络
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\" />

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/

0

精彩评论

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