我已经创建了一个表,我正在动态添加行和列。我想删除/编辑我添加的行和列。我已经包括了我的代码如何从表中动态删除/编辑行和列
$('#irow').click(function(){
if($('#row').val()){
$('#mtable tbody').append('<tr><td>Some Item</td></tr>');
$('#mtable tbody tr:last td:first').html($('#row').val());
}else{alert('Enter Text');}
});
$('#icol').click(function(){
if($('#col').val()){
$('#mtable tr').append($("<td>"));
$('#mtable thead tr>td:last').html($('#col').val());
$('#mtable tbody tr').each(function(){$(this).children('td:last').append($('<input type="text">'))});
}else{alert('Enter Text');}
});
td{padding:5px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<table border="1" id="mtable">
<thead><tr><td>Employee \department</td></tr></thead>
<tbody></tbody>
</table><br/><br/>
<input id="row" placeholder="Enter Employee Name"/><button id="irow">Add Employee</button><br/><br/>
<input id="col" placeholder="Enter department Name"/><button id="icol">Add department</button>
请帮我删除/编辑的行和列在表
您如何知道要删除哪一行或哪一列?你会有一个行索引,或...?无论如何,你不能只选择有问题的tr或tds并调用'.remove()'? – nnnnnn
是否可以删除行并编辑列? –
同样,您需要确定要删除或编辑的行或列。要更改现有单元格的内容,请使用'.html()'或'.text()'。 – nnnnnn