我有一个删除这样的行的函数:
function DeletePublisher(element, publisherid) {
jConfirm('Are you sure you want to delete this publisher?', 'Delete publisher', function (r) {
if (r) $.post('includes/publishers/delete-publisher.php?publisherid=' + publisherid,
function(data) {
if ($.trim(data) == 'error') {
$.jGrowl('This publisher was already deleted', { header: '<strong style="text-align:center;">ERROR</strong>' });
$(element).parents('tr').remove();
} else {
$(element).parents('tr').remove();
$.jGrowl('Publisher deleted');
}
});
});
现在这种方法很完美,但在删除行之后,其他行不会更新类(奇数和偶数类)。因此,在删除一行后(在此示例中,第二个TR被删除:
<tr class="odd">
<tr class="even">
<tr class="odd">
<tr class="even">
我是这样的:
<tr class="odd">
<tr class="odd">
<tr class="even">
现在我不确定这是我的错误还是我错过了什么?
答案 0 :(得分:4)
你需要再次删除所有类和addClasses再次基于奇数和
$('tr').removeClass();
// Now add class names again
$('tr:odd').addClass('odd');
$('tr:even').addClass('even');