我正在尝试从数据库创建一个表,我想创建一个按钮来删除相应的行。
我该怎么做?
<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”
答案 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();
}
}
});
});