Chrome only error: Failed to execute 'scroll' on 'Window': No function was found that matched the signature provided

Chrome only error: Failed to execute 'scroll' on 'Window': No function was found that matched the signature provided

我仅在 Chrome 中遇到此错误(在 Safari/Firefox 中有效):
Failed to execute 'scroll' on 'Window': No function was found that matched the signature provided. 代码在内联事件中:

<div onclick='function scrollToByIntoView () {
    window.scroll({
      top: 0, 
      left: 0, 
      behavior: "smooth"
    })
  };
scrollToByIntoView();'>

我不明白这是什么问题。
PS:注意这段代码是我在DOM渲染后得到的输出。实际代码是我在服务器端模板引擎中使用的不同 components/functions 中的拆分器,正如下面评论中所指出的,应该避免直接混合此代码。

也许试试 scrollTo。这是支持 x 和 y 坐标的跨浏览器。

http://www.w3schools.com/jsref/met_win_scrollto.asp

<div onclick="window.scrollTo(0,0)">...</div>

window.scroll没有选项,使用window.scrollTo。请参阅文档:

https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo

并比较

https://developer.mozilla.org/de/docs/Web/API/Window/scroll