有这样一个html:
<a class="someclass" href="some/url/absolute/or/relative">Blah</a>
...连同这样的javascript:
$("a.someclass").onclick(function() {
var link = $(this).attr("href");
if (link == window.location) // <<<<<<<<<<<<
doSomethingSpecial();
else
doOtherThing();
return false;
});
这段代码显然不起作用。
如何可靠地检测到某个锚点指向当前浏览器位置?
以下是一些注意事项:
- 锚点
href
可以是绝对的或相对的。 - URL 的片段应该被忽略。