本文介绍了如何使用jquery获取点击链接的href?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道如何通过jquery获得点击链接的href吗?我的链接如下:
Does anyone know how can I get the clicked link's href with jquery? I have the link as following:
<a href="ID=1" class="testClick">Test1.</a>
<br />
<a href="ID=2" class="testClick">Test2.</a>
<br />
<a href="ID=3" class="testClick">Test3.</a>
我编写了如下代码,以从单击的链接中获取href值.但是,即使我单击了Test2或Test3,也总是以这种方式返回第一个链接的href(ID = 1).有人知道这是怎么回事吗?以及我该如何解决这个问题?
I wrote a code as following to get the href value from the link I clicked on. But somehow this is always return me the 1st link's href (ID=1) even though I clicked on Test2 or Test3. Does anyone know what is it going on here? and how can I solve this issue?
$(".testClick").click(function () {
var value = $(".testClick").attr("href");
alert(value );
});
回调函数中的
推荐答案
this 指的是被单击的元素.
this in your callback function refers to the clicked element.
$(".addressClick").click(function () {
var addressValue = $(this).attr("href");
alert(addressValue );
});
这篇关于如何使用jquery获取点击链接的href?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!