IT技术博客大学习 共学习 共进步
全部 移动开发 后端 数据库 AI 算法 安全 DevOps 前端 设计 开发者

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

废墟 2011-09-19 23:42:51 累计浏览 3,778 次
本机暂存
$(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. translateZ() (2026-06-25 21:18:56)
  2. translateY() (2026-06-25 21:17:56)
  3. translateX() (2026-06-25 21:16:01)

查看更多 前端 文章 →

建议继续学习

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