GWT(event.getCharCode)在IE和Firefox中的行为有所不同 [英] GWT (event.getCharCode) behaves differently in IE and Firefox

查看:78
本文介绍了GWT(event.getCharCode)在IE和Firefox中的行为有所不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在浏览GWT网站上的教程用于StockWatcher应用程序,并按照步骤4:在客户端上管理事件"中所述测试应用程序.

I was going through the tutorial available on GWT website for StockWatcher application and testing the application as described in Step4: Manage Events on the Client.

下面的代码在Firefox和IE7中的行为有所不同.在IE7中,此方法效果很好,即,如果我在文本"字段中输入一些垃圾字符并按Enter键,则成功执行"event.getCharCode() == KeyCodes.KEY_ENTER"行,并且我会看到一条警报消息.但是,如果使用Firefox,则同一行无效.

Below piece of code behaves differently in Firefox and IE7. In IE7 this works well, i.e. If I enter some junk characters in Text field and hit Enter "event.getCharCode() == KeyCodes.KEY_ENTER" line gets executed successfully and I could see an alert message. However this same line does not work, if I use Firefox.

当我使用Firefox并按Enter键时,event.getCharCode返回一些垃圾字符.我在这里做错了什么?还是这种预期的行为?

When I use Firefox and press Enter, event.getCharCode returns some junk character. What am I doing wrong here? or is this expected behavior?

newSymbolTextBox.addKeyPressHandler(new KeyPressHandler() {
          public void onKeyPress(KeyPressEvent event) {
            if (event.getCharCode() == KeyCodes.KEY_ENTER) {
              addStock();
            }
          }
        });

推荐答案

使用KeyUpHandler而不是KeyPressHandler来捕获非字符键(例如Enter,Escape等).呼叫KeyUpEvent#getNativeKeyCode()获取密钥代码.

Use a KeyUpHandler instead of a KeyPressHandler to catch non-character keys (like enter, escape, etc.). Call KeyUpEvent#getNativeKeyCode() to get the key code.

这篇关于GWT(event.getCharCode)在IE和Firefox中的行为有所不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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