doutao4938 2016-05-11 09:20
浏览 23
已采纳

在jQuery中删除选定的表行

May I know how to remove table row for selected row only. For example, If I choose 2 rows to delete, it will delete the chosen rows. I have made this example but I do not know how to get the id's of the chosen row. Below are the example,

jQuery:

$("#delete").click(function(){
        var del = $("#delete").val();
        var cb=[];
        $('.checkBox:checked').each(function(){
            cb.push($(this).val()); // id's of selected checkbox to delete
        });
        $.post('delete-pr.php',
        {
            del : del,
            cb : cb
        }, function(data){
            $("#result").html(data);
            $('#myTable tr:last').remove(); // this will delete last row only
        });  
});

html:

<table id="myTable">
<tr>
<th><input type="checkbox" name="selectAll" id="selectAll" title="Select All"></th>
<th>Title</th>
<th>Type of Purchase</th>
</tr>
<?php
$sql="SELECT * FROM purchase";
$result=mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0){
    while($row=mysqli_fetch_assoc($result)){
        $pr_id=$row['pr_id'];
?>
    <tr>
    <td align="center"><input type="checkbox" name="del[]" id="checkBox" class="checkBox" value="<?php echo $row['pr_id']; ?>"></td>
    <td><?php echo $row['title']; ?></td>
    <td><?php echo $row['purchase_type']; ?></td>
    </tr>
<?php
    } 
} 
?>
</table>
  • 写回答

1条回答 默认 最新

  • dongliao8069 2016-05-11 09:27
    关注

    you can add after the success message

    function(data){
        $("#result").html(data);
        $('.checkBox:checked').each(function(){
           $(this).parent('tr').remove() ; // id's of selected checkbox to delete
        });
    });  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作