在jQuery中捕获字母和移位
我试图允许用户通过输入字段classed在jQuery中捕获字母和移位,jquery,Jquery,我试图允许用户通过输入字段classed。noNumbers,执行以下两项操作之一: 按住shift键和字母 只是按一封信 到目前为止,我的代码只允许按字母,但如果按住shift键,字母将无法通过。我不知道为什么会这样 这是我目前的代码: $(".noNumbers").keypress(function(e){ if(e.which < 97 || e.which > 122) { e.preventDefault(); } va
。noNumbers
,执行以下两项操作之一:
$(".noNumbers").keypress(function(e){
if(e.which < 97 || e.which > 122)
{
e.preventDefault();
}
var amount = $(this).val().length;
var limit = 2;
if(amount > limit)
{
e.preventDefault();
}
});
$(“.noNumbers”).按键(功能(e){
如果(e.which<97 | | e.which>122)
{
e、 预防默认值();
}
var amount=$(this).val().length;
var限值=2;
如果(金额>限额)
{
e、 预防默认值();
}
});
97
和122
是小写字母a
和z
的ASCII值。如果您想要大写字母,它们将是ASCII值65
到90
var isLetter = false;
if( (e.which >= 97 && e.which <= 122) || (e.which >= 65 && e.which <= 90) )
{
isLetter = true;
}
if(!isLetter) {
e.preventDefault();
}
var=false;
如果((e.which>=97&&e.which=65&&e.which)