如何在上/下键上阻止光标跳到文本框的开始/结束

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

本文关键字:文本 结束 开始 光标      更新时间:2023-09-26

如何使用JavaScript和jQuery防止光标在按下上下箭头键时跳到文本框的开始或结束?

<input type="text" />


$("input:text").keydown(function(e){
   if(e.which == 38 || e.which == 40) 
       e.preventDefault();
});

你可以防止默认的上下方向键。

http://jsfiddle.net/C5ZCE/

相关文章: