【问题标题】:focus({preventScroll: true}) not working in Chrome焦点({preventScroll: true})在 Chrome 中不起作用
【发布时间】:2019-02-07 18:59:07
【问题描述】:

我似乎无法让element.focus({preventScroll:true}); 在 Chrome 中工作,尽管它在 IE11 中运行良好。有没有其他人经历过这个?在 Chrome 中使用它会导致元素完全没有焦点。

【问题讨论】:

  • 您是否尝试过preventScroll:true,如this example 中所见?
  • @showdev 是的,抱歉我的代码实际上是element.focus({preventScroll:true});——我会更新我的问题。谢谢!
  • 我们可以看看你的完整代码吗?我会在 Chrome 中试一试。

标签: javascript jquery focus


【解决方案1】:

这可能与 chrome 中的 focus issues 相关

another link

如果您在 Chrome 与 Firefox 中运行文档 here 中示例中按钮的焦点代码,您会看到差异。

你可以试试:

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

但是,如果没有更多代码,很难为您调试解决方案。

【讨论】:

    猜你喜欢
    • 2013-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-17
    • 2010-11-19
    • 2017-02-06
    相关资源
    最近更新 更多