这可能是一个基本的问题......但我是jquery的新手。 我需要从表行删除下面从行中删除一列
var ptr = $(this).closest("tr")
ptr.remove("td :last")
最后一列这是为了做到这一点?
这可能是一个基本的问题......但我是jquery的新手。 我需要从表行删除下面从行中删除一列
var ptr = $(this).closest("tr")
ptr.remove("td :last")
最后一列这是为了做到这一点?
如果你想删除每行中的最后一个单元格(整列)
你可以做以下
var ptr = $("#myTable").find("tr");
ptr.find("td:last").remove();
如果您只想删除第一行中的最后一个单元格,请执行此操作
var ptr = $("#myTable").find("tr:first");
ptr.find("td:last").remove();
无论如何,我不知道你的表是如何组织的(没有源代码在你的问题)。 您应该使用thead
和tbody
进行搜索引擎优化和良好的html。
<table id="myTable">
<thead>
<tr>
<td>first column</td>
<td>second column</td>
</tr>
</thead>
<tbody>
<tr>
<td>first cell first row</td>
<td>second cell first column</td>
</tr>
<tr>
<td>first cell second row</td>
<td>second cell second column</td>
</tr>
</tbody>
</table>
您的选择器已关闭。你应该这样做,而不是:
ptr.remove("td:last");
有了空间,你将基本上是问最后所有祖先所有的TDS的的。没有空间,你说你想要所有最后的tds,这应该给你最后的td。
您可以通过细胞删除行一列。 例如:$("#yourTableId").find('tr')[RowNo].cells[ColumnNo].remove();
这里RowNo
是你的行位置从0开始到n。 和ColumnNo
是你的td从0到n没有开始。
花点时间阅读帮助中心的[编辑帮助](// stackoverflow.com/editing-help)。堆栈溢出的格式与其他站点不同。 – FrankerZ 2016-08-08 13:23:08
谢谢FrankerZ。 – 2016-09-01 11:10:19
你测试了吗? – 2011-12-21 20:32:51
你想从一行中删除最后一个*单元*或删除整列(*全部*行中的最后一个单元)? – Jacob 2011-12-21 20:41:30