有谁知道如何在 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>
最佳答案
Does anyone know how to detect the clicked href URL in JQuery?
$("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...
});
关于javascript - 如何在 JQuery/Javascript 中检测点击的 href URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12468247/