简体   繁体   English

如何将Focus设置为eventListener的tizen Web应用程序文档对象? (JavaScript)的

[英]How to set Focus to tizen web app document object for eventListener? (Javascript)

I am developing a Tizen Webapp for Watches with bezel input. 我正在开发带边框输入的手表Tizen Webapp。 To listen for the Bezel rotation event on the HTML document I used the following code: 为了侦听HTML文档上的挡板旋转事件,我使用了以下代码:

rotaryDetentCallback = function rotaryDetentHandler(e) {
    var direction = e.detail.direction;
    if (direction === "CW") {
     alert("<-");
    } else if (direction === "CCW") {
     alert("->");
    }
}; 
document.addEventListener("rotarydetent", rotaryDetentCallback, false);
  console.log(document.hasFocus());//returns true

$('select').on('change', function(){
  console.log(document.hasFocus());  //Prints false
  document.activeElement.blur();     //doesnt work
  window.focus();                    //doesnt work
  document.focus();                  //retuns error
});

The rotarydetent listener works great but after I change any Select element in the App at runtime, the document loses focus and the event is not firing any more. rotarydetent侦听器工作得很好,但是当我在运行时更改App中的任何Select元素后,文档将失去焦点,并且该事件不再触发。

How can I get the focus back to document object after select change? 选择更改后如何将焦点重新回到document对象?

PS: the standard UI for Select Tag on Tizen wearable web-apps uses the bezel also, so I guess it takes the eventListener from document and doesn't give it back. PS: Tizen可穿戴式Web应用程序上Select Tag的标准UI也使用边框,因此我想它会从文档中获取eventListener,并且不会将其返回。

There is no such function document.focus() and window.focus() is for restoring the focus to the current window ( apparently if you have multiple ones open ) and not for bringing it back to the contents of the page. 没有这样的函数document.focus()window.focus()用于将焦点恢复到当前窗口显然,如果您打开了多个 窗口 ),而不是将其带回到页面的内容。

Try to focus document.body or its focusable ancestor instead - the one being a form field , or a link or having an appropriate tabIndex attribute . 尝试聚焦document.body或其可聚焦祖先-一个是表单字段链接或具有适当的tabIndex属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM