javascript - 带有空字段的 HTML 表

标签 javascript html css string function

我目前有一个只有标题的 HTML 表格,直到添加输入,我想创建一个具有清晰行的表格,然后可以在添加数据后填充该表格。任何建议/帮助将不胜感激开始做这件事。

当前表;

需要的表;

enter image description here

表格代码;

       <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/

相关文章:

javascript - 出现在滚动问题上

css - ul li wide than browser window 强制到新行进行分页

javascript - 父级点击触发事件,子级不触发

javascript - 左侧的文本溢出省略号

javascript - 当前html页面的"mailto"

html - <img> 大于其属性

javascript - 如何使用 Angularjs $http 发布状态错误

html - div没有按顺序显示

css - Overlay 和 Box 不透明度冲突

html - 如何使用 CSS 网格对列重新排序?