我有一種感覺,這是一個令人尷尬的簡單的錯誤,但我目前看不到它。jQuery on()沒有附加標籤開火
我有一個表,我動態追加行到 - 每行的最後一列包含一個鏈接,點擊時,應該刪除該行。目前,行正在被添加罰款,但我不明白爲什麼事件附加到刪除按鈕不會觸發。我已經刪除了使用console.log()進行測試的移除代碼,但在控制檯中什麼都看不到。
我知道on()應該使用附加的HTML,我錯過了什麼?
HTML:
<div id="people">
<table>
<tr>
<th>First Name</th>
<th>Second Name</th>
<th>Age</th>
</tr>
</table>
</div>
<a href="#" id="add">Add</a>
JS:
var html = '<tr>';
html += '<td><input type="text" /></td>';
html += '<td><input type="text" /></td>';
html += '<td><input type="text" /></td>';
html += '<td><a href="#" class="remove_btn">x</a></td>';
html += '</tr>';
$('.remove_btn').on('click', function() {
console.log('REMOVE BUTTON CLICKED');
//$(this).parent().parent().remove();
return false;
});
$('#add').on('click', function() {
$('#people').append(html);
return false;
});
非常感謝人 - 這就是它!直到最近才轉移到on()以便習慣它。乾杯! (當我被允許時,會在5分鐘內接受答案) – ollie 2013-02-24 09:56:57
很好,我也不知道這個。 – cIph3r 2013-02-24 10:00:13