GWT(event.getCharCode)在IE和Firefox中的行为有所不同

编程入门 行业动态 更新时间:2024-10-26 06:28:10
本文介绍了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中的行为有所不同

本文发布于:2023-11-05 15:49:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561247.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有所不同   event   GWT   Firefox   getCharCode

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!