【发布时间】:2010-09-22 20:19:33
【问题描述】:
我有一些 jQuery/JavaScript 代码,我只想在 URL 中有哈希 (#) 锚链接时运行这些代码。如何使用 JavaScript 检查这个字符?我需要一个简单的包罗万象的测试来检测这样的 URL:
example.com/page.html#anchorexample.com/page.html#anotheranchor
基本上是这样的:
if (thereIsAHashInTheUrl) {
do this;
} else {
do this;
}
如果有人能指出我正确的方向,那将不胜感激。
【问题讨论】:
标签: javascript jquery anchor fragment-identifier