如何使用html中的行内的按钮从表中删除行?

时间:2017-01-29 14:11:15

标签: javascript php jquery html database

my screnshot

我正在尝试从数据库创建一个表,我想创建一个按钮来删除相应的行。

我该怎么做?

<tr>
    <td>
    <code><?php echo $row['id_act'];?></code>
    </td>

    <th><?php echo $row['titre_act'];?></th>
    <th><?php echo $row['description_act'];?></th>
    <th><?php echo $row['date_debut_act'];?></th>
    <th><?php echo $row['date_fin_act'];?></th>
    <th><?php echo $row['pub_act'];?></th>
    <th><a href="#" class="button button-border button-MINI button-rounded button-red" onClick="javascript:getid()"><i class=""></i></a>
        <a href="#" class="button button-border button-MINI button-rounded button-green"><i class=""></i></a></th>
</tr>

此外,每一行都从动态数据库中获取“id”

1 个答案:

答案 0 :(得分:0)

更改删除按钮html,如

<a href="#" class="button button-border button-MINI button-rounded button-red deleteRow" data-id="<?php echo $row['id_act'];?>"><i class=""></i></a>

现在可以删除行

$(document).on("click", ".deleteRow", function (e) {
    var id = $(this).attr('data-id');
    var tr = $(this).parents("tr");
   //Ajax call for delete row
      $.ajax({
        url:url     
        method:'post',
        data:{"id":id},
        success:function(data){
           if(data){
              tr.remove();
           }
        }
    });

});