简体   繁体   English

FireFox中的Sencha ExtJs TextField KeyDown事件

[英]Sencha ExtJs TextField KeyDown Event in FireFox

So I have the following code that detects where the key that was pressed is a number, space or delete key. 因此,我有以下代码可以检测到所按下的键是数字,空格或删除键。 If not it stops the key from being entered into the textfield. 如果不是,它将阻止将密钥输入到文本字段中。 It works perfectly in Chrome and IE. 它在Chrome和IE中完美运行。 When I run it in FireFox I get the following error: returnValue is undefined in the following statement: e.event.returnValue = false; 当我在FireFox中运行它时,出现以下错误:returnValue在以下语句中未定义:e.event.returnValue = false;

Here is the code: 这是代码:

keydown:function( sender, e, eOpts )
                    { 
                        if (!isNumberKey(e))
                        {
                            e.event.returnValue = false;
                        }
                    } 

The Function that does the work: 起作用的功能:

function isNumberKey(e)
{
//Local Varaible Declaration
var returnValue = false;

if (e.keyCode >= 96 && e.keyCode <= 105)
{
    returnValue = true;
}
else if (e.keyCode >= 48 && e.keyCode <= 57)
{
    returnValue = true;
}
else if (e.keyCode == 8 || e.keyCode == 46)
{
    returnValue = true;
}

return returnValue;

} }

I looked in the debugger in the firefox and found that returnValue really is not there. 我在Firefox中查看调试器,发现returnValue确实不存在。 What do I use instead? 我该怎么用呢? I am sure there must be a way to accomplish this in FireFox. 我确信必须有一种方法可以在FireFox中完成。

Thanks, 谢谢,

Josh 玩笑

It took me like 4 hours but here is the solution. 我花了大约4个小时,但这是解决方案。 Hope this helps: 希望这可以帮助:

keydown:function( sender, e, eOpts )
                        { 
                            if (!isNumberKey(e))
                            {
                                if (Ext.browser.is.Firefox) 
                                {
                                    e.event.preventDefault();
                                }
                                else
                                {
                                    e.event.returnValue = false;
                                }
                            }
                        }

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

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