只想要leftArrow右箭头和数字 [英] only want leftArrow right arrow and numbers

查看:59
本文介绍了只想要leftArrow右箭头和数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我按左箭头 event.KeyCode 给我37。

If I press left arrow event.KeyCode gives me 37.

如果按%符号 event.which 给了我37。

If I press % symbol event.which gives me 37.

在这种情况下该怎么做,我只想允许左箭头。

What to do in that situation, I only want to allow left arrow.

$('.cla').keypress(function(event) {
    var key = event.Which || event.keyCode
    if ((key >= 48 && key <= 57) || (key == 37)) {
        return true;
    } else return false;
});


推荐答案

要按%,您还需要按Shift键对吗?

In order to press % you need to also press the shift key right ?

因此,如果按下shift键,它应匹配%符号,否则匹配左箭头。
您可以使用 event.shiftKey

So if the shift key is pressed it should match the % symbol, the left arrow otherwise. You can check if the shift key is pressed with event.shiftKey

这篇关于只想要leftArrow右箭头和数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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