ハンドラーを委任するclick
か (おそらくより良い解決策)、行を作成するときにハンドラーを割り当てることができます。以下に例を示します (HTML マークアップの代わりに DOM 要素の作成を使用します。より良い方法です)。
// delegate the function once in your DOM.ready
$('#giants_table tr').on('click', 'input[type="button"][value="Remove Row"]', function (e) {
$(this).parents('tr').remove(); // this will point to the input
});
// or assign it when you create the row
function add_row(){
var input = $('<input />'), //create new DOM elements
row = $('<tr />'),
cell = $('<td />'),
rowCount = $('#giants_table tr').length;
$('#giants_table tr:last').before(tr.append(td.append(input.clone().attr({
"id": "giants_" + rowCount,
"name": "giants_" + rowCount,
"type": "text"
})).append(input.clone().attr({
"id": "removeRow" + rowCount,
"type": "button",
"value": "Remove Row"
}).click(function (e) {
$(this).parents('tr').remove(); // this now points to the input
}))));
}