文档类型不允许'th'/'td'在这里

时间:2011-11-14 22:41:30

标签: html xhtml

我正在尝试在下面显示的XHTML文档中创建一个表(为了简洁起见,仅显示相关部分):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head></head>
    <body>
      <table class="dataTable">
       <tfoot><tr><td class="tableFooter" colspan="4"><span>&copy;&nbsp;example.com</span></td></tr></tfoot>
       <tbody>
           <tr id = "firstRowHeader">
               <th class="rowLabel">&nbsp;
               <th class ="rowCol colHeader">ABC
               <th class ="rowCol colHeader">CDE
               <th class ="rowCol colHeader">EFG
           <tr><td class ="rowCategory" colspan ="4">Foo
           <tr><td class="rowLabel"
               <td class ="rowCol cellDataDown">-0.01%
               <td class ="rowCol cellDataNoChange">0.09%
               <td class ="rowCol cellDataNoChange">717.79
           <tr><td class="rowLabel"
               <td class ="rowCol cellDataUp">0.00%
               <td class ="rowCol cellDataNoChange">0.08%
               <td class ="rowCol cellDataNoChange">1,032.02
           <tr><td class="rowLabel"
               <td class ="rowCol cellDataUp">-0.04%
               <td class ="rowCol cellDataNoChange">0.03%
               <td class ="rowCol cellDataNoChange">819.17
           <tr><td class="rowLabel"
               <td class ="rowCol cellDataUp">-0.03%
               <td class ="rowCol cellDataNoChange">0.05%
               <td class ="rowCol cellDataNoChange">877.45
           <tr><td class="rowLabel"
               <td class ="rowCol cellDataUp">-0.00%
               <td class ="rowCol cellDataNoChange">0.09%
               <td class ="rowCol cellDataNoChange">991.57
           <tr><td class="rowLabel"
               <td class ="rowCol cellDataUp">-0.02%
               <td class ="rowCol cellDataNoChange">0.05%
               <td class ="rowCol cellDataNoChange">835.42
           <tr><td class="rowLabel"
               <td class ="rowCol cellDataUp">0.00%
               <td class ="rowCol cellDataNoChange">0.05%
               <td class ="rowCol cellDataNoChange">1,002.40
           <tr><td class="rowLabel"
               <td class ="rowCol cellDataDown">-0.01%
               <td class ="rowCol cellDataNoChange">0.05%
               <td class ="rowCol cellDataNoChange">860.27
       </tbody>
      </table>

    </body>
</html>

当我通过w3c验证器运行此doc时,我遇到了多种错误 - 文档类型不允许'th'(或'td')。有人可以指出如何解决这个问题吗?

6 个答案:

答案 0 :(得分:6)

您未使用<td><tr>关闭任何</tr></td>个代码。此外,您错过了>所有<td>代码的{{1}}。

答案 1 :(得分:0)

您未关闭<td><tr>代码。

答案 2 :(得分:0)

您没有关闭代码。每个</th></td>都需要相应的<th><td>。这应该是它的样子:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head></head>
    <body>
      <table class="dataTable">
       <tfoot><tr><td class="tableFooter" colspan="4"><span>&copy;&nbsp;example.com</span></td></tr></tfoot>
       <tbody>
           <tr id = "firstRowHeader">
               <th class="rowLabel">&nbsp;</th>
               <th class ="rowCol colHeader">ABC</th>
               <th class ="rowCol colHeader">CDE</th>
               <th class ="rowCol colHeader">EFG</th>
           </tr>
           <tr><td class ="rowCategory" colspan ="4">Foo</td></tr>
           <tr><td class="rowLabel"></td>
               <td class ="rowCol cellDataDown">-0.01%</td>
               <td class ="rowCol cellDataNoChange">0.09%</td>
               <td class ="rowCol cellDataNoChange">717.79</td>
           </tr>
           <tr><td class="rowLabel"></td>
               <td class ="rowCol cellDataUp">0.00%</td>
               <td class ="rowCol cellDataNoChange">0.08%</td>
               <td class ="rowCol cellDataNoChange">1,032.02</td>
           </tr>
           <tr><td class="rowLabel"></td>
               <td class ="rowCol cellDataUp">-0.04%</td>
               <td class ="rowCol cellDataNoChange">0.03%</td>
               <td class ="rowCol cellDataNoChange">819.17</td>
           </tr>
           <tr><td class="rowLabel"></td>
               <td class ="rowCol cellDataUp">-0.03%</td>
               <td class ="rowCol cellDataNoChange">0.05%</td>
               <td class ="rowCol cellDataNoChange">877.45</td>
           </tr>
           <tr><td class="rowLabel"></td>
               <td class ="rowCol cellDataUp">-0.00%</td>
               <td class ="rowCol cellDataNoChange">0.09%</td>
               <td class ="rowCol cellDataNoChange">991.57</td>
           </tr>
           <tr><td class="rowLabel"></td>
               <td class ="rowCol cellDataUp">-0.02%</td>
               <td class ="rowCol cellDataNoChange">0.05%</td>
               <td class ="rowCol cellDataNoChange">835.42</td>
           </tr>
           <tr><td class="rowLabel"></td>
               <td class ="rowCol cellDataUp">0.00%</td>
               <td class ="rowCol cellDataNoChange">0.05%</td>
               <td class ="rowCol cellDataNoChange">1,002.40</td>
           </tr>
           <tr><td class="rowLabel"></td>
               <td class ="rowCol cellDataDown">-0.01%</td>
               <td class ="rowCol cellDataNoChange">0.05%</td>
               <td class ="rowCol cellDataNoChange">860.27</td>
           </tr>
       </tbody>
      </table>

    </body>
</html>

答案 3 :(得分:0)

您永远不会关闭每一行中的第一个<td>。变化

<tr><td class="rowLabel"

<tr><td class="rowLabel">

此外,您必须关闭标记元素。表格如下:

<table>
<tr><th>header</th></tr>
<tr><td>content</td></tr>
</table>

答案 4 :(得分:0)

您的文件格式不正确。您需要关闭<th><td><tr>代码....

示例:

<tr id = "firstRowHeader">
   <th class="rowLabel">&nbsp;</th>
   <th class ="rowCol colHeader">ABC</th>
   <th class ="rowCol colHeader">CDE</th>
   <th class ="rowCol colHeader">EFG</th>
</tr>

答案 5 :(得分:0)

    

<body>
  <table class="dataTable">
   <thead>
      <tr id = "firstRowHeader">
           <th class="rowLabel">&nbsp;</th>
           <th class ="rowCol colHeader">ABC</th>
           <th class ="rowCol colHeader">CDE</th>
           <th class ="rowCol colHeader">EFG</th>
      </tr>
   </thead>
   <tfoot>
     <tr>
       <td class="tableFooter" colspan="4"><span>&copy;&nbsp;example.com</span></td>
     </tr>
   </tfoot>
   <tbody>
       <tr>
       <td class ="rowCategory" colspan ="4">Foo</td>
       </tr>
       <tr><td class="rowLabel"></td>
           <td class ="rowCol cellDataDown">-0.01%</td>
           <td class ="rowCol cellDataNoChange">0.09%</td>
           <td class ="rowCol cellDataNoChange">717.79</td>
       </tr>
       <tr><td class="rowLabel"></td>
           <td class ="rowCol cellDataUp">0.00%</td>
           <td class ="rowCol cellDataNoChange">0.08%</td>
           <td class ="rowCol cellDataNoChange">1,032.02</td>
       </tr>
       <tr><td class="rowLabel"/>
           <td class ="rowCol cellDataUp">-0.04%</td>
           <td class ="rowCol cellDataNoChange">0.03%</td>
           <td class ="rowCol cellDataNoChange">819.17</td>
       </tr>
       <tr><td class="rowLabel"></td>
           <td class ="rowCol cellDataUp">-0.03%</td>
           <td class ="rowCol cellDataNoChange">0.05%</td>
           <td class ="rowCol cellDataNoChange">877.45</td>
       </tr>
       <tr><td class="rowLabel"/>
           <td class ="rowCol cellDataUp">-0.00%</td>
           <td class ="rowCol cellDataNoChange">0.09%</td>
           <td class ="rowCol cellDataNoChange">991.57</td>
       </tr>
       <tr><td class="rowLabel"/>
           <td class ="rowCol cellDataUp">-0.02%</td>
           <td class ="rowCol cellDataNoChange">0.05%</td>
           <td class ="rowCol cellDataNoChange">835.42</td>
       </tr>
       <tr><td class="rowLabel"></td>
           <td class ="rowCol cellDataUp">0.00%</td>
           <td class ="rowCol cellDataNoChange">0.05%</td>
           <td class ="rowCol cellDataNoChange">1,002.40</td>
       </tr>
       <tr><td class="rowLabel"></td>
           <td class ="rowCol cellDataDown">-0.01%</td>
           <td class ="rowCol cellDataNoChange">0.05%</td>
           <td class ="rowCol cellDataNoChange">860.27</td>
       </tr>
   </tbody>
  </table>

</body>