jQuery/JS 键码:一个 IF 语句中的多个键码
我正在尝试为我正在开发的应用程序设置一些键码,但这确实让我发疯。
我正在尝试设置键码,从 keyCode 65 到 91 、 44 、 47 以及其他一些键码都可以工作。
所以我有这个:
var e = event || evt;
if ((e.keyCode > 65 || e.Keycode < 91)){
// Do function
}
它可以找到。现在,如果我尝试添加另一个键码,它不起作用。 这就是我尝试过的:
if ((e.keyCode > 65 || e.Keycode < 91) && (e.keyCode == 44) && (e.keyCode == 47)){
有人帮助我在一个 If 语句中添加不同的键码吗?
多谢
I'm trying to set up some keycodes for an app I'm working on but it really drives me crazy.
I'm trying to set up keycodes which would say, from keyCode 65 to 91 , 44 , 47 and few others, do function.
So I have this:
var e = event || evt;
if ((e.keyCode > 65 || e.Keycode < 91)){
// Do function
}
which works find. Now if I try to add another keycode it doesn't work.
This is what I tried:
if ((e.keyCode > 65 || e.Keycode < 91) && (e.keyCode == 44) && (e.keyCode == 47)){
Does someone help me to add different keycodes in one If statement?
Thanks alot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个
如果条件逻辑让您困惑,我认为您最好考虑一下您想要包含(而不是排除)的数字。将它们分成多个范围并将每个范围放在自己的行上。从伪代码开始:
然后填写条件:
Try this
If the conditional logic is tripping you up, I think you might be best served by thinking about the numbers you want to include (not exclude). Break them into ranges and put each range on its own line. Start with pseudo code:
Then fill in the conditions:
如果您想要从 31 到 90 的所有值(除了从 48 到 57 的值):
现在可以等效地写为:
If you want everything from 31 to 90 except for those from 48 through 57:
Now that could be written equivalently as: