[英]Javascript detect keypress keycode unprintable keys
this.inputText.on('keypress', function(e){
if ( String.fromCharCode(e.keyCode)) { //or e.keyCode == ""
valid = true;
console.log(true);
} else {
valid = false;
console.log(false);
}
});
I try to detect when keypress, key is printable key (unprintable key - like ctrl + a, or arrow up)我尝试检测何时按键,键是可打印的键(不可打印的键 - 如 ctrl + a 或向上箭头)
but It never return fasle when I press unprintable key, like arrow down但是当我按下不可打印的键时它永远不会返回 fasle,比如向下箭头
anyone know how to achieve this?有谁知道如何实现这一目标?
Use keydown
, not keypress
.使用
keydown
,而不是keypress
。 The whole point of keypress
is that it's for keys that result in a printable character. keypress
的全部意义在于它用于产生可打印字符的键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.