我的 jQuery 代码有问题。当我进行附加时,事件单击仅适用于第一个 img,而不是新的(附加的)。
我的代码page.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");
});
非常感谢你 !