用jQuery删除表行最好的方法是什么?
当前回答
这无疑是最简单的方法:
$("#your_tbody_tag").empty();
其他回答
简单. .试试这个
$("table td img.delete").click(function () {
$(this).parent().parent().parent().fadeTo(400, 0, function () {
$(this).remove();
});
return false;
});
$('tr').click(function()
{
$(this).remove();
});
我认为你会尝试上面的代码,因为它工作,但我不知道为什么它工作了一段时间,然后整个表被删除。我还试图通过单击该行删除该行。但找不到确切的答案。
这无疑是最简单的方法:
$("#your_tbody_tag").empty();
$('#myTable tr').click(function(){
$(this).remove();
return false;
});
甚至是更好的
$("#MyTable").on("click", "#DeleteButton", function() {
$(this).closest("tr").remove();
});
从表中删除行最简单的方法:
使用表的唯一ID删除行。 根据该行的顺序/索引进行删除。例如:删除第三行或第五行。
例如:
<table id='myTable' border='1'>
<tr id='tr1'><td>Row1</td></tr>
<tr id='tr2'><td>Row2</td></tr>
<tr id='tr3'><td>Row3</td></tr>
<tr id='tr4'><td>Row4</td></tr>
<tr id='tr5'><td>Row5</td></tr>
</table>
//======REMOVE TABLE ROW=========
//1. remove spesific row using its ID
$('#tr1').remove();
//2. remove spesific row using its order or index.
//row index started from 0-n. Row1 index is 0, Row2 index is 1 and so on.
$('#myTable').find('tr:eq(2)').remove();//removing Row3