我正在使用 append 将数据附加到表中。我希望能够删除我一一追加的每一行。但是它现在的工作方式是删除所有孩子。我究竟做错了什么?
<table class="" width="300" border="0" cellpadding="0" cellspacing="0">
<tr><th>Date</th><th>Pokemanz</th><th align="right" style="text-align:right;">Value</th></tr>
<tr><td style="width:62px;"><input type="text"
class="transactions_date" size="15" value="4/5/12"/>
</td><td><input type="text" class="transaction_title" size="30"
value="Pickachu"/></td><td align="right">
<input type="text" class="transactions_amount" size="10" value="$25"/></td></tr>
</table>
<div class="new_transaction"></div>
<input type="button" value ="Add Transaction" id="add_trans"/>
<input type="button" value ="Delete Transaction" id="delete_trans" />
</p>
(function() {
$('#add_trans').on('click',function () {
$('.new_transaction').append('<tr><td style="width:62px;"><input type="text" class="transactions_date" size="15" value=""/></td><td> <input type="text" class="transaction_title" size="30" value=""/></td><td align="right"><input type="text" class="transactions_amount" size="10" value=""/></td></tr>');
});
$('#delete_trans').on('click',function () {
$('.new_transaction').children().each(function () {
$(this).remove(); // "this" is the current element in the loop
});
});
})();