我如何知道哪个GWT元素具有焦点? [英] How do i find out which GWT element has focus?

查看:98
本文介绍了我如何知道哪个GWT元素具有焦点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在GWT中找出哪些元素当前有重点。基本上我在我们的应用程序中使用虚拟键盘。所有的键都可以正常工作,除了Tab键。如果我获得焦点元素,那么我可以制定出tab键代码。

在javascript和jquery中,我们可以使用 document.activeElement code>。希望有些机构会以正确的方式实现这一目标。



请大家谅解。

解决方案

在所有浏览器中不受支持的事实只在您的应用针对所有浏览器时才重要。 activeElement目前支持不少浏览器为什么GWT中没有isFocused() ?



我需要类似的东西,我需要从小部件内部知道它是否有焦点。我做了以下内容:

  protected native boolean hasFocus(Element element)/ *  -  {
return element.ownerDocument.activeElement ==元素;
} - * /;

我需要传入当前元素以获取正确的文档,只需调用

  document.activeElement; 

没有给我我需要的文件。你可能会做同样的事情,但传入一个不同的元素(RootPanel元素也许?),并返回焦点元素,而不是一个布尔。

  protected native Element elementInFocus(Element element)/ *  -  {
return element.ownerDocument.activeElement;
} - * /;


I would like to find out, in GWT, which element currently has focus. Basically i was working on virtual keyboard in our application. All keys are working fine except tab key. If i get focused element then i can work out the tab key code.

In javascript and jquery we can get this using document.activeElement. Hope some body will put me in right way to achieve this.

Help would be appreciated.

解决方案

The fact that it's not supported in "all browsers" is only important if your app is targeting all browsers. activeElement is currently supported by quite a few browsers Why is there no isFocused() in GWT?.

I needed something similar, I needed to know from inside a widget if it had focus. I did the following

protected native boolean hasFocus(Element element) /*-{
   return element.ownerDocument.activeElement == element;
}-*/; 

I needed to pass in the current element to get the proper document, just calling

document.activeElement;

did not give me the document I needed. You could likely do the same but pass in the a different element (RootPanel element maybe?) and return the in focus Element rather than a bool.

protected native Element elementInFocus(Element element) /*-{
   return element.ownerDocument.activeElement;
}-*/; 

这篇关于我如何知道哪个GWT元素具有焦点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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