开发者

jquery ajax - dynamic button(s) onclick event

I'm making an ajax call that is pulling back a table of items, each row begins with an edit button. I want to assign an "onclic开发者_Go百科k event" or equivalent to each of these edit buttons so that they pass the specific item id to a function...which will in turn make another ajax call to pull specific info about that item. I've read several postings that use .live but have failed to see any that allows a specific id to be passed in so that dynamic data can be pulled. Any thoughts?


Try something like this. I am assuming the edit button in a td within tr and there is an itemId attribute for each tr to be used to make a ajax call on button click.

The below code is using live so that when you add update the table or add more rows to this table the edit button click will be fired for all the buttons without even attaching the new events.

$("editButtonSelector").live("click", function(){
   var itemId = $(this).closest("tr").attr("itemId");
   //Now use this itemId to pass to the ajax call you make.
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜