繁体   English   中英

jQuery DataTable 删除带有 ID 的 Tr

[英]jQuery DataTable delete Tr with ID

我的桌子

<table id="grid">
    <thead>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Position</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody>
        <tr id="row1">
            <td>Tiger Nixon</td>
            <td>System Architect</td>
            <td><button onclick="doDeleteClick('row1')">Delete</button></td>
        </tr>
        <tr id="row2">
            <td>Garrett Winters</td>
            <td>Accountant</td>
            <td><button onclick="doDeleteClick('row2')">Delete</button></td>
        </tr>
        <tr id="row3">
            <td>Ashton Cox</td>
            <td>Junior Technical Author</td>
            <td><button onclick="doDeleteClick('row3')">Delete</button></td>
        </tr>
    </tbody>
</table>

在一个函数中,我试过

$('#grid').DataTable().row($('#row-2')).remove().draw();

使用一个函数通过发送参数来执行,如何连续执行?

只需创建这样的按钮

<button data-id="some-unique-id" class="removeBtn">Delete</button>

然后使用简单的jquery

$(".removeBtn").on('click', function(){
    $(this).closest('tr').remove();
    var id = $(this).attr('data-id');
    //Do something with the id
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM