仅在键是字母或数字时才对键进行警报 [英] do an alert on keyup only if the key is a letter or number

查看:63
本文介绍了仅在键是字母或数字时才对键进行警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想在按键事件时显示警报,但前提是按键是字母或数字,而不是shift,tab等.

I would like to show an alert on keyup event but only if the key was a letter or a number, not for shift,tab etc.

<input type='text' id='hi />

或除Tab,Shift,Ctrl以外的任何其他键,请输入

or for any key except for tab, shift, ctrl, enter

有人知道吗?

推荐答案

您将必须在文本框中附加一个"keyup"事件,并在事件内部检查

You will have to attach an "keyup" event to the textbox and inside the event check for the keycodes you want:

$("#hi").bind("keyup", function(e) {
       //on letter number
       if (e.which <= 90 && e.which >= 48)
       {
          alert('hello');
       }
});

这篇关于仅在键是字母或数字时才对键进行警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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