从数据表中删除一行

osc*_*ady 3 html javascript jquery

我试图用jQuery删除一行id="data(Number)"从数据表中选择如何.那可能,或者id<tr>标签上更好,而不是<td>标签?

<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered">
    <thead>
        <tr>
            <th>Check</th>
            <th>Field_1</th>
            <th>Field_2</th>
            <th>Field_3</th>
        </tr>
    </thead>
    <tbody id="dataTable">
        <tr>
            <td><input type='checkbox' id='data1'><br></td>
            <td>Field_1_Input1</td>
            <td>Field_2_Input1</td>
            <td>Field_3_Input1</td>
        </tr>
        <tr>
            <td><input type='checkbox' id='data2'><br></td>
            <td>Field_1_Input2</td>
            <td>Field_2_Input2</td>
            <td>Field_3_Input2</td>
        </tr>
    </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

laa*_*sto 5

尝试:

 function removerow(number){
    $('#data'+number).closest('tr').remove();
}
Run Code Online (Sandbox Code Playgroud)

然后你可以调用例如removerow(2)删除带有input元素的行id=data2

DEMO

更新(来自评论)

td使用$("#data"+i)try 获取行中的元素文本:

$('#data' + number).parent().siblings().each(function () {
        console.log($(this).text());
});
Run Code Online (Sandbox Code Playgroud)

DEMO2