如何在JQuery/Javascript中检测所点击的href URL

3

有没有人知道如何在JQuery中检测已点击的href URL?例如,我有以下链接,一些是重定向到新页面,一些调用JavaScript扩展div。如果没有使用ID,我该如何使用JQuery/Javascript检测href。

<a href="www.test.com">Test 1</a>
<a href="javascript:test()">Test 2</a>
<a href="www.test2.com">Test 3</a>
<a href="www.test3.com">Test 4</a>
<a href="javascript:test2()">Test 5</a> 

4
“检测 href” 是什么意思? - Ram
1
我对“selected”这个词感到困惑。你是在谈论当有人使用Tab键移动可选对象时吗?还是,你想要检测哪一个被点击了? - demersus
1个回答

7
有人知道如何在JQuery中检测点击的href URL吗?
$("a").click(function(event){
    // Capture the href from the selected link...
    var link = this.href;

    alert(link);

    // do something if required....

    // would prevent the link from executing, if that is something you want to do...
    return false; // not needed if you want the link to execute normally...
});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接