是否有一个jQuery函数可以使您转到#name,就像您建立指向href =“#name”的链接一样,所以我可以在准备好文档的情况下直接转到#name
最佳答案
您可以只更改location.hash,如下所示:
$(function() {
window.location.hash = '#name'; //works with or without the # included
});
尽管如果只是超链接到页面,则这是内置的浏览器行为,例如转到
http://site.com/page.html#name
将具有相同的加载时滚动效果。