查看 com.google.gwt.dom.client.NativeEvent extends JavaScriptObject
,如何检测事件是否为数字?
我想到了 Character.isDigit(event.getKeyCode())
,但这会给我一个错误:
The method isDigit(char) in the type Character is not applicable for the arguments (int)
我还能怎样检测到他的呢? 我为此使用 GWT Java。
最佳答案
解决方案1
addKeyPressHandler( new KeyPressHandler()
{
public void onKeyPress( KeyPressEvent event )
{
char charCode = event.getCharCode();
if ( Character.isDigit( charCode ) )
{
System.out.println("This is a digit!!!");
}
}
}
解决方案2
public void onBrowserEvent( com.google.gwt.cell.client.Cell.Context context, Element parent, String value, NativeEvent event, ValueUpdater<String> valueUpdater )
{
if ( "keypress".equals( event.getType() ) )
{
int charCode = event.getCharCode();
if ( !Character.isDigit( ( char ) charCode ) )
{
System.out.println("This is a digit!!!");
}
}
super.onBrowserEvent( context, parent, value, event, valueUpdater );
}
关于java - 如何检测 NativeEvent 中的数字键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14789437/