gpt4 book ai didi

php - 在php中删除行

转载 作者:行者123 更新时间:2023-11-27 23:39:04 25 4
gpt4 key购买 nike

我创建了一个警报系统,如果有意的话,我打算在其中提供消除警报的可能性。

我有以下删除按钮和表格:

<button type="button" name="Delete" Onclick="if(confirm('Tem certeza de que deseja excluir esta Mensagem?')) deletar();" class="btn btn-primary"><i class="glyphicon glyphicon-envelope"></i><i class="glyphicon glyphicon-remove-sign"></i></button>

<table class="table table-responsive table-striped table-bordered table-condensed table-hover">
<thead>
<tr>
<th>De</th>
<th>Assunto</th>
<th>Prioridade</th>
<th>Recebido</th>
</tr>
</thead>
<thead>
<tr>
<?php
do {
if ($nomede != $produto["De"]) {
?>
<th width="10%" colspan=4>Recebido: <?php echo $produto["Data"]; ?></th>
<?php
$nomede = $produto["De"];
}
?>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $produto["De"]; ?></td>
<td class="td-info view_data apagar" id="<?php echo $produto["Id"]; ?>,<?php echo $produto["Para"]; ?>" data-toggle="modal" href="#dataModal" width="20%" <?php echo $produto["Status"] != '0' ? ' style="font-weight:bold; font-size: 90%" ' : ' style="font-weight:normal; font-size: 90%" ' ?>><?php echo $produto["Assunto"]; ?></td>
<td><?php echo $produto["Prioridade"]; ?></td>
<td><?php echo $produto["Hora"]; ?></td>
</tr>
<?php } while ($produto = $resultado_cursos->fetch_assoc()); ?>
</tbody>
</table>

要删除我想选择该行,选择时更改该行的颜色然后删除,为此,我正在执行以下操作:

jQuery:

function deletar() {
var ids = []; //arraypara armazenar os id's a serem deletados
$(".colorir").each(function() { //percorre todos os tr que possui a classe colorir
ids.push($(this).find(".apagar").attr("Id")); //adiciona o id da linha ao array
$(this).remove();
})

$.ajax({
url: './deletealerta',
type: 'POST',
cache: false,
data: {
ids: ids
},
error: function() {

},
success: function(result) {}
});
}

CSS:

.colorir {
background-color:#81BEF7;
}

我遇到的问题是它没有选择表中的行来标识 id 并能够通过单击删除按钮将其删除。您选择的唯一一行是按日期分隔的行,如图所示:

enter image description here

但是分隔日期的这一行选择没有意义,因为我无法删除它。我找不到我在哪里只能选择这些日期线。

问题是,因为它没有选择该行,所以它没有返回该函数的行 ID,以便能够删除该行。但我不知道如何解决这个问题。

最佳答案

您需要一种方法来检测您是要删除该行还是不只是向您的日期行添加一个类

<th width="10%" colspan=4 class="do-not-delete">Recebido: <?php echo $produto["Data"]; ?></th>

然后在你的删除函数中你可以检查一下

$(".colorir").each(function() { //percorre todos os tr que possui a classe colorir
if(!$(this).hasClass(".do-not-delete")){
ids.push($(this).find(".apagar").attr("Id")); //adiciona o id da linha ao array
$(this).remove();
}
})

关于php - 在php中删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57111822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com