简体   繁体   English

focus({preventScroll: true}) 在 Chrome 中不起作用

[英]focus({preventScroll: true}) not working in Chrome

I can't seem to get element.focus({preventScroll:true});我似乎无法获得element.focus({preventScroll:true}); to work in Chrome although it's working perfectly in IE11.尽管它在 IE11 中运行良好,但仍可在 Chrome 中工作。 Has anyone else experienced this?有没有其他人经历过这种情况? Using this in Chrome results in the element not becoming focused at all.在 Chrome 中使用它会导致元素根本没有聚焦。

It probably has to due with focus issues in chrome这可能是由于 chrome 中的焦点问题造成的

another link 另一个链接

If you run the focus code for buttons from the example in the docs here in Chrome vs Firefox, you'll see the difference.如果您在文档中运行从例如对于按钮的焦点代码这里在Chrome VS Firefox中,你会看到其中的差别。

you can try:你可以试试:

window.setTimeout(function ()
{
  document.getElementById('element').focus({preventScroll:true});
}, 0);

However without more code its hard to debug a solution for you.但是,如果没有更多代码,就很难为您调试解决方案。

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

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