我正在浏览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中的行为有所不同
发布评论