Unk*_*own 5 javascript jquery gwt
我想在GWT中找出目前关注的元素.基本上我在我们的应用程序中使用虚拟键盘.除tab键外,所有键都正常工作.如果我得到聚焦元素,那么我可以计算出tab键代码.
在javascript和jquery中我们可以使用它document.activeElement.希望有些机构会让我以正确的方式实现这一目标.
帮助将不胜感激.
只有当您的应用定位到所有浏览器时,"所有浏览器"都不支持这一事实.很多浏览器目前支持activeElement 为什么GWT中没有isFocused()?.
我需要类似的东西,我需要从小部件内部知道它是否有焦点.我做了以下
protected native boolean hasFocus(Element element) /*-{
return element.ownerDocument.activeElement == element;
}-*/;
Run Code Online (Sandbox Code Playgroud)
我需要传入当前元素来获取正确的文档,只需调用即可
document.activeElement;
Run Code Online (Sandbox Code Playgroud)
没有给我我需要的文件.你可能会做同样的事情,但传入一个不同的元素(RootPanel元素可能?)并返回焦点元素而不是bool.
protected native Element elementInFocus(Element element) /*-{
return element.ownerDocument.activeElement;
}-*/;
Run Code Online (Sandbox Code Playgroud)
document.activeElement不适用于所有浏览器,因此 GWT 不支持该功能。您也许可以使用 focus&blur 处理程序来跟踪哪个元素拥有它。