Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 如何使用 jQuery 或 Javascript 将 HTML 页面滚动到给定的锚点?
我正在使用 Sammy.js,它处理所有客户端 URL 导航。我想导航到/page#fragment,但页面实际上不会去#fragment。我怎样才能让它做到这一点,无论是自动的,还是通过编写代码去片段?
/page#fragment
#fragment
Sammy 不会自动触发路由,因此您需要在处理程序中添加:
hash = window.location.hash if(hash != '') { window.location.hash = hash; }