Jquery禁用键盘键 [英] Jquery disabling a keyboard key

查看:87
本文介绍了Jquery禁用键盘键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能通过使用jquery禁用某个键盘键(如星号或字符串)?

t禁用关键笔划,但可以使用jQuery捕获它并覆盖它的操作(返回false)。下面的示例捕获输入密钥。

  $(input)。keypress(function(evt){ 

var keycode = evt.charCode || evt.keyCode;
if(keycode == 13){//输入键的键码
返回false;
}
});


Is it possible to disable a certain keyboard key (like asterisk or string) by using jquery?

解决方案

You can't disable a key stroke as such but you could capture it with jQuery and overwrite its action (return false). The example below captures the enter key. Just change 13 to any key code you need to disable.

$("input").keypress(function (evt) {

  var keycode = evt.charCode || evt.keyCode;
  if (keycode  == 13) { //Enter key's keycode
    return false;
  }
});

这篇关于Jquery禁用键盘键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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