【发布时间】:2010-06-25 09:23:24
【问题描述】:
我有这个表结构
<table id="latest" class="debt">
<thead>
<tr>
<th width="50">Credor</th>
<th width="50">Devedor</th>
<th>Motivo</th>
<th width="80">Valor</th>
<th width="10"></th>
</tr>
</thead>
<tbody>
<?php foreach ($this->latest as $latest) { ?>
<tr <?php if ($latest->reg_value < 0) { echo "class='error'"; } ?>>
<td><?php echo $latest->findParentRow('Application_Model_DbTable_Names','Creditor')->nam_name; ?></td>
<td><?php echo $latest->findParentRow('Application_Model_DbTable_Names','Debtor')->nam_name; ?></td>
<td><?php echo $latest->reg_reason; ?></td>
<td>R$ <?php echo number_format(abs($latest->reg_value), 2, ',', ' ')?></td>
<td><a href="#" id="<?php echo $latest->reg_id; ?>" class="delete"><img src="http://192.168.0.102/libraries/css/blueprint/plugins/buttons/icons/cross.png" alt=""/></a></td>
</tr>
<?php } ?>
</tbody>
</table>
每一行都有一个删除按钮,它使用 AJAX 并删除 tr 元素本身。发生的情况是:当所有行都被删除时,tbody 可能会变为空,当这种情况发生时,我想删除所有表。
我知道有一个伪选择器$('#latest tbody:empty'),但这只会选择tbody。当 tbody 为空或类似时,我想选择整个表。
回答后编辑
我在删除所有行后检查了元素:标签内只有和 thead 标签。尽管如此,它并没有删除表格元素。看代码
// TR Fading when deleted
$('.delete').live('click', function() {
$.ajax({
type: 'POST',
url: 'history/delete/id/'+$(this).attr('id')
});
$(this).closest('tr').fadeOut('slow', function() {
$(this).remove();
if($(this).closest('table').find('tbody').is(':empty'))
$('#latest').remove();
});
return false;
});
【问题讨论】:
标签: javascript jquery