html - 如何在表格中正确插入 <div> 和 <tr>?

标签 html html-table

我在网上查了没找到答案,所以才来问这个问题。

新数据将始终按照以下格式进行格式化,并填充到 id="content"

<tr>
   <td>name</td>
   <td>age</td>
   <td>gender</td>
</tr>

我读到你需要 <div><td> 里面如果你要放<div><table> 里面.现在,格式不正确。所有新数据都在第一列,而不是每一行。

<table>
   <tr>
      <th>name</th>
      <th>age</th>
      <th>gender</th>
   </tr>
   <td>
      <div id="contents">
         <tr>
            <td>John</td>
            <td>12</td>
            <td>male</td>
         </tr>
         <tr>
            <td>Jess</td>
            <td>13</td>
            <td>female</td>
         </tr>
      </div>
   <td>
</table>

最佳答案

更新

重新阅读您最可能需要的结构

<table>
  <thead>
   <tr>
      <th>name</th>
      <th>age</th>
      <th>gender</th>
   </tr>
  </thead>
  <tbody id="contents">
     <tr>
        <td>John</td>
        <td>12</td>
        <td>male</td>
     </tr>
     <tr>
        <td>Jess</td>
        <td>13</td>
        <td>female</td>
     </tr>
  </tbody>
</table>

原始答案

您不能将 tr 作为 div 的直接子级。

你需要使用表格

要么

<table>
   <tr>
      <th>name</th>
      <th>age</th>
      <th>gender</th>
   </tr>
   <td>
      <table id="contents">
       <tr>
          <td>John</td>
          <td>12</td>
          <td>male</td>
       </tr>
       <tr>
          <td>Jess</td>
          <td>13</td>
          <td>female</td>
       </tr>
      </table>
   <td>
</table>

<table>
   <tr>
      <th>name</th>
      <th>age</th>
      <th>gender</th>
   </tr>
   <td>
      <div id="contents">
       <table>
        <tr>
          <td>John</td>
          <td>12</td>
          <td>male</td>
        </tr>
        <tr>
          <td>Jess</td>
          <td>13</td>
          <td>female</td>
        </tr>
       </table>
      </div>
   <td>
</table>

关于html - 如何在表格中正确插入 <div> 和 <tr>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28867001/

相关文章:

jQuery 数据表检查

javascript - 仅在页面刷新后加载 Jquery 脚本

html - 两个元素使用完全相同的样式,但颜色略有不同

javascript - IE 没有在 onblur 事件中调用函数

r - gt 表中的字体在 R Shiny 应用程序中不起作用

html - 居中 <table> 主体,而列是文本对齐的 : left?

HTML 表格宽度。

php - JQUERY AJAX 为每个循环自定义属性

javascript - 如何使用 jquery 启用/禁用 div 层

css - 为什么 TD 显示在同一行的 TR 显示中?