【发布时间】:2013-06-28 17:16:53
【问题描述】:
我的 jQuery 代码有问题。当我进行追加时,事件点击只对第一个 img 起作用,而不是新的(追加的)。
我的代码页.htm:
<img src="images/del.png" style="cursor:pointer;" title="Delete" class="delegate-del"/>
<img src="images/add.png" style="cursor:pointer;" title="Add" class="delegate-add" />
我的代码 jQuery:
// When we click on "add.png", the script add the image del.png
$('.delegate-add').click(function(){
$('#tableautest').append('<img src="images/del.png" style="cursor:pointer;" title="Delete" class="delegate-del" />');
});
/* The alert just work on the first balise <img src="images/del.png"...
I don't understand why that's don't work with the new img appended... An idea ??
*/
$('.delegate-del').click(function(){
alert("ok");
});
非常感谢!
【问题讨论】: