我有一个表格,每当用户单击开始事件按钮时都会显示数据,但我需要知道当用户再次单击开始按钮时如何附加记录,以前的记录将被覆盖
这是我的 JavaScript 代码
function DisplayData(downTime) {
console.log(downTime);
var newContent = '';
$.each(downTime.data, function (i, item) {
newContent += Hesto.Html.StartTR(item.downTime);
newContent += Hesto.Html.CreateTD(item.CategoryName);
newContent += Hesto.Html.CreateTD(item.StartTime);
newContent += Hesto.Html.CreateTD(item.EndTime);
newContent += Hesto.Html.CreateTD(item.Comments);
newContent = Hesto.Html.EndTR(newContent);
});
$('#DowntimeList').html(newContent);
}
这是我的 html 代码:
<table id="Downtimetable" class="hesto">
<thead>
<tr>
<th>End Of DownTime</th>
<th>Category Name</th>
<th>Start Time</th>
<th>End Time</th>
<th>Comments</th>
</tr>
</thead>
<tbody id="DowntimeList">
</tbody>
<tfoot>
</tfoot>
</table>
最佳答案
使用append()
而不是覆盖html()
:
$('#DowntimeList').append(newContent);
关于javascript - 在 javascript 中附加一个表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23104237/