javascript window.location id

use*_*331 3 html javascript window.location

我想让浏览器滚动div的id

<div id="test">
   lol
</div> 
Run Code Online (Sandbox Code Playgroud)

所以我使用这段代码

window.location = "#test";
Run Code Online (Sandbox Code Playgroud)

但我现在的网址是这样的

http://locahost/index.html#test
Run Code Online (Sandbox Code Playgroud)

是否可以删除"#test"但是去那?

Ble*_*der 6

滚动到元素:

document.querySelector('#test').scrollIntoView();
Run Code Online (Sandbox Code Playgroud)