$.focus() not working in chrome

馋奶兔 提交于 2019-12-22 08:57:16

问题


In chrome's developer tools console I'm selecting an input[type="text"] element, then trying to focus on it eg $('input#foo').focus(). It doesn't work, no error is thrown but the element isn't focused.

I spent half an hour trying to figure out the problem so am posting this in order to help others who have this 'problem' since I didn't find an answer on SO.


回答1:


The reason this happens is that the main part of the page isn't allowed to take focus away from the dev tools window, so when you're in the console tab, the main part of the page can't take focus away from it.

Very annoying, run your code in a script and it should work.



来源:https://stackoverflow.com/questions/17484276/focus-not-working-in-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!