我学习了新的 “window.location.hash” 并在我的 jquery 代码中尝试而不是 “window.location.href” ,它们都给出了相同的结果。
代码在这里:
window.location.href = ($(e.currentTarget).attr("href"));
window.location.hash = ($(e.currentTarget).attr("href"));
它们之间有什么区别?
原文由 kalaba2003 发布,翻译遵循 CC BY-SA 4.0 许可协议
对于像
http://[www.example.com]:80/search?q=devmo#test
这样的 URLhash
返回 URL 中#
符号之后的部分,包括#
符号。您可以侦听hashchange
_事件_,以获取支持浏览器中散列更改的通知。href
返回整个 URL。阅读更多