我有一個問題,我的jQuery代碼。當我做一個追加,事件點擊只是在第一個img上工作,而不是新的(appened)。追加後點擊事件不起作用,爲什麼?
我的代碼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");
});
非常感謝你!
不錯!這很好!非常感謝你 ! – Geoffrey