jQuery: How to capture the TAB keypress within a Textbox

前端 未结 9 1543
迷失自我
迷失自我 2020-11-30 19:32

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

9条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 19:43

    Suppose you have TextBox with Id txtName

    $("[id*=txtName]").on('keydown', function(e) { 
      var keyCode = e.keyCode || e.which; 
      if (keyCode == 9) {
         e.preventDefault();
         alert('Tab Pressed');
     }
    }); 
    

提交回复
热议问题