繁体   English   中英

使用给定的JavaScript在Firefox中无法使用箭头键

[英]Arrow keys not working in firefox with given javascript

我有一个编码如下的文本框:

<input name="txttelephone" type="text" maxlength="16" id="txttelephone" class="InputTextBox" onkeypress="return NumbersOnly(event);" required />

和javascript函数如下所示:

function NumbersOnly(e) {
    var unicode = e.charCode ? e.charCode : e.keyCode;
    if (unicode != 8) {
        if (unicode < 48 || unicode > 57) {

            if (unicode == 9)
                return true;
            else
                return false;
        }
    }
}

现在,当我在chrome箭头键中运行正常时,但在Firefox箭头键中却无法运行。 没有得到什么问题。

请帮我解决一下这个。

谢谢,

蒂帕

您必须排除箭头键代码。 尝试在代码中进行以下修改。

function NumbersOnly(e) {
    var unicode = e.charCode ? e.charCode : e.keyCode;
    if (unicode != 8) {
        if (unicode < 48 || unicode > 57) {

            if (unicode == 9 || IsArrows(e) )
                return true;
            else
                return false;
        }
    }
}
function IsArrows (e) {
       return (e.keyCode >= 37 && e.keyCode <= 40); 
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM