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 == 13){
          e.preventDefault(); //Skip default behavior of the enter key
          var nextIndex = $input.index(this) + 1;
          if(nextIndex < n)
              $input[nextIndex].focus();
          else
              $input[nextIndex-1].blur();
    }
  });
}

 

参考:





posted @ 2016-12-30 11:40  HTL  阅读(6898)  评论(0编辑  收藏  举报
htl