我无法使用动态生成的按钮删除表中的一行。主要问题是“alert()”不起作用。我如何捕捉“点击”事件?
jQuery:
$("#officers-table").on('click', '.remove-officer-button', function(e) {
var whichtr = $(this).closest("tr");
alert('worked'); // Alert does not work
whichtr.remove();
});
HTML/PHP(更新了代码)
<table id="officers-table" class="ui-widget ui-widget-content">
<?php if($num_officers > 0): ?>
<thead>
<tr class="ui-widget-header ">
<th>Name</th>
<th>Director</th>
<th>Shareholder</th>
<th>Secretary</th>
<th colspan="2">Options</th>
</tr>
</thead>
<?php endif; ?>
<tbody>
<?php foreach ($officers as $item): ?>
<tr>
<td><?=$item->name?> <?=$item->lastname?></td>
<td><?=$item->is_director?></td>
<td><?=$item->is_shareholder?></td>
<td><?=$item->is_secretary?></td>
<td>Edit</td>
<td><button type="button" value="<?=$item->id?>" class="remove-officer-button">Remove</button></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>