$("#target").click(function () {
var removecolunms = $("#textval").val();
$('table colgroup').find('col:eq("' + removecolunms + '")').remove();
$('table tr').find('th:eq("' + removecolunms + '")').remove();
$('table tr').find('td:eq("' + removecolunms + '")').remove();
});
$('table').find('tr').each(function() {
this.removeChild(this.cells[ 0 ]);
});
where
0
是columnIndex
$('tr').each(function(){
$(this).find('td:nth-child(' + colIndex + ')').remove();
$(this).find('th:nth-child(' + colIndex + ')').remove();
});
检查Fiddle
<table border="1" style="width:100%" class="dataupdate">
<tr>
<td>Row 1 Col1</td>
<td>Row 1 Col2</td>
<td>Row 1 Col3</td>
<td>Row 1 Col4</td>
<td>Row 1 Col5</td>
<td>Row 1 Col6</td>
</tr>
<tr>
<td>Row 2 Col1</td>
<td>Row 2 Col2</td>
<td>Row 2 Col3</td>
<td>Row 2 Col4</td>
<td>Row 2 Col5</td>
<td>Row 2 Col6</td>
</tr>
<tr>
<td>Row 3 Col1</td>
<td>Row 3 Col2</td>
<td>Row 3 Col3</td>
<td>Row 3 Col4</td>
<td>Row 3 Col5</td>
<td>Row 3 Col6</td>
</tr>
</table>
<form>
<input type="text" id="numrow" placeholder="Row" >
<input type="text" id="numcol" placeholder="Column">
<input type="button" id="removeButton" value="Remove" >
</form>
$('#removeButton').click(
function(){
var numrow = $('#numrow').val();
var numcol = $('#numcol').val();
$('.dataupdate tr:nth-child('+numrow+') td:nth-child('+numcol+')').remove()
});
FiddleHttp://jsfiddle.net/yy7qmedt/1/
function deleteColumn(tableEl, colIndex) {
for (let row of tableEl.rows) {
row.deleteCell(colIndex)
}
}
<table id="table">
<tr>
<th><button id="btn" onclick="deleteColumn(table, 0)"><code>deleteColumn(table, 0)</code></button></th>
<th><button id="btn" onclick="deleteColumn(table, 1)"><code>deleteColumn(table, 1)</code></button></th>
</tr>
<tr>
<td>Foo</td>
<td>42</td>
</tr>
<tr>
<td>Bar</td>
<td>666</td>
</tr>
</table>