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

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

问题描述

我想在 GWT 中找出当前具有焦点的元素.基本上我正在我们的应用程序中使用虚拟键盘.除了 Tab 键外,所有键都工作正常.如果我获得焦点元素,那么我可以计算出选项卡键代码.

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.

在 javascript 和 jquery 中,我们可以使用 document.activeElement 获得它.希望某些机构能让我以正确的方式实现这一目标.

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

帮助将不胜感激.

推荐答案

仅当您的应用面向所有浏览器时,所有浏览器"都不支持它这一事实才重要.目前很多浏览器都支持activeElement 为什么GWT中没有isFocused()?.

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;

没有给我我需要的文件.您可能会做同样的事情,但传入不同的元素(可能是 RootPanel 元素?)并返回焦点元素而不是 bool.

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天全站免登陆