jQuery:如何捕获文本框中的TAB按键 [英] jQuery: How to capture the TAB keypress within a Textbox

查看:143
本文介绍了jQuery:如何捕获文本框中的TAB按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想捕获TAB按键,取消默认操作并调用我自己的javascript函数。

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

推荐答案

编辑:由于您的元素是动态插入的,因此您必须使用委派( ) ,如您的示例所示,但您应该将其绑定到keydown事件,因为在@Marc注释时,在IE中,按键事件不会捕获非字符键:

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
  } 
});

查看示例这里

这篇关于jQuery:如何捕获文本框中的TAB按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆