我有一些 jQuery/JavaScript 代码,我只想在 URL 中有哈希 ( #
) 锚链接时运行。如何使用 JavaScript 检查这个字符?我需要一个简单的包罗万象的测试来检测这样的 URL:
example.com/page.html#anchor
example.com/page.html#anotheranchor
基本上是这样的:
if (thereIsAHashInTheUrl) {
do this;
} else {
do this;
}
原文由 Philip Morton 发布,翻译遵循 CC BY-SA 4.0 许可协议
位置哈希 的简单使用: