admin管理员组文章数量:1426810
I would like a jQuery function to know which link was clicked to call it, i.e. I would like the link's id value to be passed to the jQuery function.
Is this possible? If so what is the neatest way to do it.
I would like a jQuery function to know which link was clicked to call it, i.e. I would like the link's id value to be passed to the jQuery function.
Is this possible? If so what is the neatest way to do it.
Share Improve this question asked Dec 8, 2009 at 7:34 AnkurAnkur 51.2k115 gold badges248 silver badges316 bronze badges4 Answers
Reset to default 4Sure. Inside the click()
event handler you can refer to the element clicked by this
.
$("a").click(function() {
alert(this.id);
...
});
or
$("a").click(function() {
alert($(this).attr("id"));
...
});
$("a").click(function() {
var linkid = $(this).attr("id");
// use linkId here
});
Don't forget to cancel default behaviour, or you won't achieve nothing.
$("a").click(function(e) {
e.preventDefault();
var linkid = $(this).attr("id");
//do whatever here
});
$("a").click(function() {
alert($(this).attr("id"));
...
});
i can say this same..
本文标签: javascriptHow to pass a variable from a link to a jQuery functionStack Overflow
版权声明:本文标题:javascript - How to pass a variable from a link to a jQuery function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745478372a2660066.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论