javascript - HTML/JS Table-Header 与 Table-Body 不匹配
问题描述
我在正确显示表格时遇到了一点问题。表头与表体不一致。表格日期显示在 1/3/5/7 列中,因此奇数列被跳过,我知道为什么会发生这种情况。
相关代码:
HTML代码:
<div id="accreqlist" hidden="true">
<h1>Accountanfragen Liste</h1>
<button class="btn btn-secondary btn-lm" id="accreqreturnbtn">zurück</button>
<form id="accreqlist_form">
<div id=accreq_message class="form__message form__message--error"></div>
</form>
<table class="tablelist" id="tblAccList">
<thead>
<tr>
<th>Accountanfrage ID</th>
<th>Name</th>
<th>E-Mail</th>
<th>Mobile</th>
<th>Action 1</th>
<th>Action 2</th>
</tr>
</thead>
<tbody>
<!--will get filled through js file-->
</tbody>
</table>
</div>
JS代码:
function accountRequestlistclicked() {
$.getJSON("/api/accountRequests").done(handleAccountRequestlistReply);
}
function handleAccountRequestlistReply(reqs) {
$("#tblAccList tbody").empty();
for (let req of reqs) {
addReqToList(req);
}
}
function addReqToList(req) {
let id = req["accountRequestId"];
var newRow = "<tr>";
newRow += "<td>" + req["accountRequestId"] + "<td>";
newRow += "<td>" + req["accountRequestName"] + "<td>";
newRow += "<td>" + req["accountRequestEmail"] + "<td>";
newRow += "<td>" + req["accountRequestMobile"] + "<td>";
newRow +=
"<td> <button id = 'u" +
req["accountRequestId"] +
"' onClick='deleteAccRequest(" +
req["accountRequestId"] +
")'> Delete </button> </td>";
newRow +=
"<td> <button id = 'u" +
req["accountRequestId"] +
"' onClick='createUser(" +
req["accountRequestId"] +
")'> Account erstellen </button> </td>";
newRow += "</tr>";
$("#tblAccList tbody").append(newRow);
}
//accreq löschen
function deleteAccRequest(id) {
var urlstring = "/api/deleteAccountRequest/" + id;
$.ajax({
type: "DELETE",
url: urlstring,
success: deleteReqRespons,
dataType: "json",
contentType: "application/json",
});
}
//user erstellen
function createUser(id) {
var urlstring = "api/createUser/" + id;
$.ajax({
type: "Post",
url: urlstring,
success: createUserResponse,
dataType: "json",
contentType: "application/jsin",
});
}
有人知道我如何修复表格,以便正确显示列吗?
我非常感谢每一个输入!
解决方案
我知道出了什么问题。我忘了关闭 td-tags。所以对于每个</th>
丢失的数据:((很抱歉偷了你的时间,这个简单的问题。干杯
推荐阅读
- .net - 为什么 SwaggerForOcelot 不加载服务 swagger 端点 .NET 6?
- javascript - Discord 机器人不发送问候消息
- docker - 将 docker 数据库卷共享到不同的 PC
- c# - Azure 服务总线 - 发布到队列和事务范围内的主题
- insertion-sort - 仅使用 java.util.Scanner 的 JAVA 插入排序
- python - 查找多个网页的所有日期/事件
- batch-file - 如何检查批处理文件中的变量是否包含某个字符串
- php - 特征中递归方法中的名称冲突
- linux - 如何以编程方式污染 Linux 内核?
- docker - 运行 Docker 映像时缺少端口?