获取按键的键值 [英] Get key value of a key pressed
本文介绍了获取按键的键值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我找不到如何获得按键值的方法. 我目前有
I don't find how to get the value of a key pressed. I currently have
$('#info_price').bind('keydown',function(evt){
alert(evt.keyCode);
但是当我按1而不是返回"1"时,它将返回"49".
but it return '49' when I press on 1 instead of returning '1'.
我知道键'1'的Ascii代码.
I'm aware that Ascii code of key '1'.
最终目标是使人们只能在输入中输入数字.所以我想检测非数字而不显示它们.
The final goal is to allow people to only write digit into the input. So i want to detect the non digit and not display them.
推荐答案
如注释中所述,它是ASCII
代码.要将其作为角色,您可以这样做:
As it's told in comment it's ASCII
code. To get it as character you can do:
alert(String.fromCharCode(evt.keyCode));
这篇关于获取按键的键值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文