jquery实现的回车(Enter)替换为Tab键

废墟 2011-09-19 23:42:51 累计浏览 3,931 次
$(document).ready(function () {
  $(':input:text:first').focus();
  $(':input:enabled').addClass('enterIndex');
  // get only input tags with class data-entry
  textboxes = $('.enterIndex');
  // now we check to see which browser is being used
  if ($.browser.mozilla) {
    $(textboxes).bind('keypress', CheckForEnter);
  } else {
    $(textboxes).bind('keydown', CheckForEnter);
  }
});
function CheckForEnter(event) {
  if (event.keyCode == 13 && $(this).attr('type') != 'button' && $(this).attr('type') != 'submit' && $(this).attr('type') != 'textarea' && $(this).attr('type') != 'reset') {
    var i = $('.enterIndex').index($(this));
    var n = $('.enterIndex').length;
    if (i < n - 1) {
      if ($(this).attr('type') != 'radio')
      {
        NextDOM($('.enterIndex'),i);
      }
      else {
        var last_radio = $('.enterIndex').index($('.enterIndex[type=radio][name=' + $(this).attr('name') + ']:last'));
        NextDOM($('.enterIndex'),last_radio);
      }
    }
    return false;
  }
}
function NextDOM(myjQueryObjects,counter) {
  if (myjQueryObjects.eq(counter+1)[0].disabled) {
    NextDOM(myjQueryObjects, counter + 1);
  }
  else {
    myjQueryObjects.eq(counter + 1).trigger('focus');
  }
}

同分类推荐文章

  1. Embracing Playful Imperfection With The CSS `random()` Function (2026-11-14 03:10:02)
  2. Document Picture-in-Picture API与任意元素画中画实现 (2026-11-13 17:10:02)
  3. 给博客做个站内全文搜索:纯前端离线倒排索引的设计与取舍 (2026-10-03 16:40:31)

查看更多 前端 文章 →

建议继续学习

  1. JQuery实现Excel表格呈现 (累计阅读 48,734)
  2. 深入理解Javascript之执行上下文(Execution Context) (累计阅读 18,922)
  3. 从输入 URL 到页面加载完成的过程中都发生了什么事情? (累计阅读 16,397)
  4. 图片动态局部毛玻璃模糊效果的实现 (累计阅读 15,180)
  5. 天朝第二代身份证号码的验证机制 (累计阅读 15,106)
  6. HTML 5 的data-* 自定义属性 (累计阅读 14,741)
  7. 分享一个JQUERY颜色选择插件 (累计阅读 14,550)
  8. 什么是全栈工程师? (累计阅读 14,414)
  9. 快速排序(Quicksort)的Javascript实现 (累计阅读 12,102)
  10. 7 天打造前端性能监控系统 (累计阅读 11,782)