确定“退格”按钮按下 [英] Determine "Backspace" button pressing

查看:99
本文介绍了确定“退格”按钮按下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在GWT中确定用户按下了 Backspace 按钮?我尝试了这一点,但它不起作用

  @Override 
public void onKeyPress(KeyPressEvent event){
char charCode = event.getCharCode();
if(charCode ==(char)KeyCodes.KEY_BACKSPACE){
// do someThing
}
}

解决方案

在大多数浏览器中, keypress 会产生角色(这就是它的标准化方式: http://www.w3.org/TR/DOM-Level-3-Events/#event-type-keypress )。退格显然不会产生一个字符;你应该使用 keydown keyup 来检测它。


How to determine in GWT that user pressed Backspace button? I tried this, but it does not work

  @Override
  public void onKeyPress(KeyPressEvent event) {
       char charCode= event.getCharCode();
       if(charCode == (char) KeyCodes.KEY_BACKSPACE){
           //do someThing 
       }
  }

解决方案

The keypress event is implemented in most browsers as only firing when a character would be produced (and that's how it's being standardized: http://www.w3.org/TR/DOM-Level-3-Events/#event-type-keypress ). Backspace obviously doesn't produce a character; you should use keydown or keyup to detect it.

这篇关于确定“退格”按钮按下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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