关键code中显示不正确Angularjs code值 [英] keyCode displaying incorrect code value in Angularjs
问题描述
我正在拍摄pssed与模糊搜索结果中使用的API密钥$ P $。
反正我用这个code捕捉到我的标记和指令控制器关键presses:
<输入类型=文本
占位=搜索
NG-点击=searchPop($事件)
吴键preSS =typingMainSearch($事件)>
vs.typingMainSearch =功能(E){
的console.log(e.key code);
vs.searchPopoverDisplay = TRUE;
};
然而,当我键入 A
我得到 97
,当我输入 B
我得到 98
。
这些都是我比较它们到任何地方我看网上不正确的值。
HTTP:// WWW。 cambiaresearch.com/articles/15/javascript-char-$c$cs-key-$c$cs
<一个href=\"http://stackoverflow.com/questions/25464579/is-it-possible-to-listen-for-arrow-keys$p$pss-using-ng-key$p$pss\">Is它可以使用NG键preSS监听箭头键preSS?
为什么会出现这种情况? 是假设为 65 和乙是假设为 66
VAR键= {
'A':65,
'B':66,
C:67,
D:68,
'E':69,
'F':70,
G:71,
'H':72,
'我':73,
J:74,
'K':75,
L:76,
'M':77,
N:78,
'O':79,
'P':80,
Q:81,
'R':82,
'S':83,
'T':84,
'U':85,
V:86,
W:87,
X:88,
Y:89,
Z:90
}
我想你要找的是什么 NG-KEYUP
来代替,这会为你工作:
&LT;输入类型=文本
占位=搜索
NG-点击=searchPop($事件)
NG-KEYUP =typingMainSearch($事件)&GT;
根据 Mozilla的中的键preSS的关键code
属性是pcated德$ p $。
此外 - 这就是为什么你看到的97时,点击A,例如(来自Mozilla的链接获取):
键的UNI code编号;
块引用>您可以找到UNI code编号表的这里
I'm working on capturing keys pressed to use with an API for fuzzy search results.
Anyways I'm using this code to capture keypresses in my Markup and Directive Controller:
<input type="text" placeholder="Search" ng-click="searchPop($event)" ng-keypress="typingMainSearch($event)">
vs.typingMainSearch = function(e) { console.log(e.keyCode); vs.searchPopoverDisplay = true; };
However when I type
a
I get97
, when I typeb
I get98
.
Those are incorrect values when I compare them to any place I look online.
http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
Is it possible to listen for arrow keyspress using ng-keypress?
Why is this the case? a is suppose to be 65 and b is suppose to be 66:
var key = { 'a': 65, 'b': 66, 'c': 67, 'd': 68, 'e': 69, 'f': 70, 'g': 71, 'h': 72, 'i': 73, 'j': 74, 'k': 75, 'l': 76, 'm': 77, 'n': 78, 'o': 79, 'p': 80, 'q': 81, 'r': 82, 's': 83, 't': 84, 'u': 85, 'v': 86, 'w': 87, 'x': 88, 'y': 89, 'z': 90 }
解决方案I think what you're looking for is
ng-keyup
instead, this will work for you:<input type="text" placeholder="Search" ng-click="searchPop($event)" ng-keyup="typingMainSearch($event)">
According to Mozilla the
keyCode
property of keypress is deprecated.Also - this is why you saw 97 when clicking 'a' for instance (taken from the Mozilla link):
The Unicode reference number of the key;
You can find the unicode numbering table here.
这篇关于关键code中显示不正确Angularjs code值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!