我目前有一个只有标题的 HTML 表格,直到添加输入,我想创建一个具有清晰行的表格,然后可以在添加数据后填充该表格。任何建议/帮助将不胜感激开始做这件事。
当前表;
需要的表;
表格代码;
<div>
<table id="requestContents">
<colgroup>
<col style="width: 128px">
<col style="width: 136px">
<col style="width: 84px">
<col style="width: 113px">
<col style="width: 123px">
</colgroup>
<tr>
<th>Request ID</th>
<th>Request Type</th>
<th>Blood Type</th>
<th>Notice</th>
<th>Request Date</th>
</tr>
</table>
</div>
这就是我向表中添加数据的方式;
ipcRenderer.on('Request:DonorInformation', function(event, requestType, bloodType, Notice) {
var datetime = currentdate.getDate() + "/"
+ (currentdate.getMonth()+1) + "/"
+ currentdate.getFullYear() + " "
+ currentdate.getHours() + ":"
+ currentdate.getMinutes()
var table = document.getElementById("requestContents");
const createRow = document.createElement('tr')
const requestIDAdd = document.createElement('td')
const requestTypeAdd = document.createElement('td')
const bloodTypeAdd = document.createElement('td')
const noticeAdd = document.createElement('td')
const dateAdd = document.createElement('td')
const requestID = document.createTextNode(" ")
const requestTypeText = document.createTextNode(requestType)
const bloodTypeText = document.createTextNode(bloodType)
const NoticeText = document.createTextNode(Notice)
const dateText = document.createTextNode(datetime)
requestIDAdd.appendChild(requestID)
requestTypeAdd.appendChild(requestTypeText)
bloodTypeAdd.appendChild(bloodTypeText)
noticeAdd.appendChild(NoticeText)
dateAdd.appendChild(dateText)
createRow.appendChild(requestIDAdd)
createRow.appendChild(requestTypeAdd)
createRow.appendChild(bloodTypeAdd)
createRow.appendChild(noticeAdd)
createRow.appendChild(dateAdd)
table.appendChild(createRow)
})
最佳答案
添加一个新的 <tr>
有 5 个空 <td>
在里面(每行要添加一次):
<table>
...
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
关于javascript - 带有空字段的 HTML 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54915486/