admin管理员组文章数量:1410724
I have the following jQuery
$('#btnDelete').click( function() {//Do the delete here via jquery post});
In my table I have numerous rows with the following
<a id="btnDelete">Delete</a>
How I do I pass parameters to the click event to post an ID to delete something
I have the following jQuery
$('#btnDelete').click( function() {//Do the delete here via jquery post});
In my table I have numerous rows with the following
<a id="btnDelete">Delete</a>
How I do I pass parameters to the click event to post an ID to delete something
Share Improve this question asked May 15, 2009 at 20:59 JonJon 40.1k87 gold badges243 silver badges393 bronze badges2 Answers
Reset to default 4If you have many of these, the easiest way to tie a handler to them all is to have them all share a mon class rather than a mon ID (id's should be unique...).
<a class="btnDelete" id="del_123">Delete</a>
<a class="btnDelete" id="del_124">Delete</a>
<a class="btnDelete" id="del_125">Delete</a>
Then to activate them, you can bind a click event:
$(function() {
$(".btnDelete").click(function() {
// get your id here
var $id = parseInt(this.id.substring(4));
// POST with your info or whatever... and then...
return false;
});
});
You could use this wrapped in jQuery function. Inside your callback:
$(this)
will be a wrapped set containing the a tag that trigger the event. For example if, you have this structure:
<tr><td><a id="btnDelete">Delete</a></td></tr>
$(this).parent()
will contain the parent td element. You can then use its id or attributes. This is much better than trying to pass parameters to the callback.
本文标签: javascriptPassing Parameters to jQuery Delete Button Click EventHandlerStack Overflow
版权声明:本文标题:javascript - Passing Parameters to jQuery Delete Button Click EventHandler - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744834409a2627545.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论