IT技术博客大学习 共学习 共进步

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

废墟 2011-09-19 23:42:51 浏览 3,722 次
$(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. JQuery实现Excel表格呈现 (阅读 48,164)
  2. 分享一个JQUERY颜色选择插件 (阅读 14,063)
  3. jQuery插件---轻量级的弹出窗口wBox. (阅读 10,625)
  4. 10个强大的Ajax jQuery文件上传程序 (阅读 8,724)
  5. jQuery性能优化指南 (阅读 8,646)
  6. jQuery的data()方法 (阅读 8,504)
  7. jQuery Color Animations颜色动画插件 (阅读 8,345)
  8. 精于图片处理的10款jQuery插件 (阅读 7,262)
  9. 配合jquery实现异步加载页面元素 (阅读 6,285)
  10. jQuery中getJSON跨域原理详解 (阅读 6,264)