gpt4 book ai didi

javascript - 在 javascript 中附加一个表格

转载 作者:行者123 更新时间:2023-11-28 19:53:09 25 4
gpt4 key购买 nike

我有一个表格,每当用户单击开始事件按钮时都会显示数据,但我需要知道当用户再次单击开始按钮时如何附加记录,以前的记录将被覆盖

这是我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com