Jquery 实现input回车时跳转到下一个input元素

时间:2023-03-09 06:33:00
Jquery 实现input回车时跳转到下一个input元素
/**
* 回车时跳转到下一个元素
* @Author HTL
* @DateTime 2016-12-30T11:33:25+0800
* @param {[type]} $input [INPUT 元素列表]
* @return {[type]} [description]
*/
function keydown_to_tab($input){
if(!$input) $input = $('input:text:not(:disabled)');
$input.bind("keydown", function(e) {
var n = $input.length;
if (e.which == ){
e.preventDefault(); //Skip default behavior of the enter key
var nextIndex = $input.index(this) + ;
if(nextIndex < n)
$input[nextIndex].focus();
else
$input[nextIndex-].blur();
}
});
}
参考: