javascript window.location id

时间:2013-07-05 04:49:13

标签: javascript html window.location

我想让浏览器滚动div的id

<div id="test">
   lol
</div> 

所以我使用这段代码

window.location = "#test";

但我的网址现在就像这样

http://locahost/index.html#test

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

1 个答案:

答案 0 :(得分:6)

滚动到元素:

document.querySelector('#test').scrollIntoView();