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

时间:2016-12-30 13:00:52   收藏:0   阅读:664
 
 
/**
 * 回车时跳转到下一个元素
 * @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();
    }
  });
}

 

参考:
how-to-set-focus-on-next-textbox-on



From WizNote



原文:http://www.cnblogs.com/huangtailang/p/6236258.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!