如何启用其他键的输入 [英] How to enable input for additional keys

查看:23
本文介绍了如何启用其他键的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已在此处

function isNumberKey(evt)
{
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode != 46 && charCode > 31
        && (charCode < 48 || charCode > 57))
        return false;
    return true;
}


function isCharKey(evt)
{
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode != 46 && charCode > 31
        && (charCode < 48 || charCode > 57))
        return true;
    return false;
}

它们的目标是仅允许将数字或仅文本字符输入到输入字段中.我刚刚发现这还排除了 del backspace 之类的功能键.我如何在这里添加它们?

The goal of them is to only allow input of either numbers or only textcharacters into an input field. I just discovered this also excludes functional keys like del and backspace. How would I add them here?

推荐答案

delete和Backspace的密钥代码分别为46和8.因此,您可以创建和修改现有功能

The key code for delete and backspace is 46 and 8 respectively. So you can create and modify the existing function

function allowDelBack(evt){
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode === 46 || charCode ===8)
        return false;
    return true;
}

这篇关于如何启用其他键的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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