I want to capture the TAB keypress, cancel the default action and call my own javascript function.

推荐答案

Edit: Since your element is dynamically inserted, you have to use delegated on() as in your example, but you should bind it to the keydown event, because as @Marc comments, in IE the keypress event doesn't capture non-character keys:

$("#parentOfTextbox").on('keydown', '#textbox', function(e) { 
  var keyCode = e.keyCode || e.which; 

  if (keyCode == 9) { 
    e.preventDefault(); 
    // call custom function here
  } 
});

Check an example here.

Jquery相关问答推荐

退出 jquery.each 循环后

如何从 jQuery 转到 React.js?

在 for 循环中分配点击处理程序

在范围内设置文本

jQuery 动画滚动

jQuery - 获取 ajax POST 的表单值

jQuery切换CSS?

如何使用 jQuery UI Resizable 仅水平或垂直调整大小?

jquery:更改URL地址而不重定向?

在 JQuery .trigger 上传递参数

如何使用 jQuery 从 div 中删除 id 属性?

如何签入用户已在 Google recaptcha 中选中复选框的 js?

Rails 5:如何将 $(document).ready() 与 turbo-links 一起使用

jQuery .hasClass() 与 .is()

JavaScript 等效于 jQuery 的扩展方法

Jquery Select 所有具有 $jquery.data() 的元素

使用 jQuery Select 空文本输入

将多个参数传递给 jQuery ajax 调用

如何使用 ID 变量在 jQuery 中 Select 元素?

jquery追加到列表的前面/顶部