weixin_33698823 2019-07-19 11:42 采纳率: 0%
浏览 43

删除PHP中的行

I created a system of alerts, where I intend to give the possibility to eliminate the alert if it is intended.

I have the following delete button and table:

<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>

To delete I want to select the line, changing the color of the line when selecting and then delete, for this, I am doing the following:

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;
}

The problem I have is that it does not select the row in the table to identify the id and be able to delete it by clicking the delete button. The only line you select is the line that separates by date as shown in the image:

enter image description here

But this line separating the date does not make sense to select because I can not delete it. I am not finding where I am to just select these date lines.

The problem is, since it does not select the line it does not return the line id for the function to be able to delete the line. But I do not know how to solve the problem.

  • 写回答

1条回答 默认 最新

  • 笑故挽风 2019-07-19 13:15
    关注

    What you need is a way to detect if you want to delete the row or not just add a class to your date row

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

    and then in your delete function you can check like

    $(".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();
        }
    })
    
    评论

报告相同问题?

悬赏问题

  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形