【发布时间】:2016-12-28 18:13:42
【问题描述】:
我正在尝试使用此方法https://datatables.net/examples/api/add_row.html,我的表格由几个不同的 HTML 元素组成,它们属于 select 和 input 类型。我在这里将其简化为一个输入和一列。我的目标是单击“添加行”按钮并将包含所有元素的确切行添加到表中。但是当我单击“添加行”按钮时,条目数会增加,在控制台中没有错误或警告,但我仍然没有看到新行被添加到表中。
<table id="myTable">
<thead>
<tr>column header 1</tr>
<tr>column header 2</tr>
</thead>
<tbody>
<tr id="myRow">
<td id="colorField>
<input id="color">
</td>
</tr>
</tbody>
</table>
JS部分:
$(document).ready(function() {
var t = $('#myTable').DataTable();
$('#addRow').on('click', function(){
var jRow = $('#myRow');
jRow.id = "myRow2"; //I thought about changing the id but also not effective
t.row.add(jRow).draw();
});
});
【问题讨论】:
标签: javascript jquery datatables row