【问题标题】:html table td's and tr's disappearinghtml 表 td 和 tr 消失
【发布时间】:2016-10-25 05:56:21
【问题描述】:

我正在经历一些非常奇怪的事情。我正在开发一个聊天系统,其中包含基于表格的行和内容,但格式一直很混乱。我想知道为什么,直到我查看了不工作的源部分,它看起来像这样:

<table border="0"> 
<tbody> 

<tr class="chatline" style="background:white;border-style:none;border-top:1px solid grey;padding:0px;"> 
<td style="background:#A0D7FF;margin:0px;width:1%;"><span style="padding:2px;background:#A0D7FF;color:black;height:100%;border-right:1px solid grey;">kpsuperplane</span></td> 
<td style="color:black;background:white;"><span style="color:black;padding:2px;">test</span></td> 
</tr> 
<tr class="chatline" style="background:white;border-style:none;border-top:1px solid grey;padding:0px;"> 
<td style="background:#A0D7FF;margin:0px;width:1%;"><span style="padding:2px;background:#A0D7FF;color:black;height:100%;border-right:1px solid grey;">kpsuperplane</span></td> 
<td style="color:black;background:white;"><span style="color:black;padding:2px;">test</span></td> 
</tr> 
</tbody>
</table>

但是,当我通过 chrome 中的开发工具查看它时,我得到了这个:

 <table border="0"> 
    <tbody> 
    <span style="padding:2px;background:#A0D7FF;color:black;height:100%;border-right:1px solid grey;">kpsuperplane</span>
<span style="color:black;padding:2px;">test</span>
   <span style="padding:2px;background:#A0D7FF;color:black;height:100%;border-right:1px solid grey;">kpsuperplane</span>
<span style="color:black;padding:2px;">test</span>
    </tbody>
    </table>

知道为什么会这样吗? td 和 tr 在呈现时会自动从文档中删除。这不是特定于 chrome 的。 Dreamweaver 中的实时代码给出了同样令人费解的结果。 下图:

【问题讨论】:

标签: html html-table tablerow


【解决方案1】:

我在 jsfiddle 中对此进行了测试,似乎没有问题。我还在自己的环境(chrome)中对其进行了测试,效果很好。尝试在表格上方的代码中查找未闭合的标记。

编辑:

将代码粘贴到 w3c 验证器 http://validator.w3.org/check。我在 html 中发现了 13 个错误/警告。查看错误和具体的行号。

我发现table 中有div 标签,但它们没有被tr 包裹。我相信您将能够在验证器输出中找到其余部分。

【讨论】:

  • +1。顺便说一句,缺少引号( " )也可能会产生这个奇怪的问题,尽管正如 Trevor 所提到的,不是像
    或类似的封闭标签通常是代码在 chrome 中呈现奇怪但在 Firefox 中很好的主要原因
  • 谢谢。我在我的代码中发现了一个语法错误,我已经修复了它。有点尴尬,我自己从来没有发现过。
  • 【解决方案2】:

    根据你的jsfiddle:你的HTML结构有一个简单的错误,这里是复制粘贴;

     </tr> 
    </table> 
    </div> 
    
    <tr class="chatline" style="background:white;border-style:none;border-top:1px solid    grey;padding:0px;"> 
    

    你关闭表,然后你不打开它。 ctrl + f 并输入 /table。我建议您仔细阅读并制作有效的 html ;)

    【讨论】:

      【解决方案3】:

      对不起,这不是一个答案,但它不会让我发表评论。

      我使用开发工具在 chrome 中尝试了相同的代码,它向我显示了 tr 和 td,所以我不是你的情况。我将上面的代码包含在 html 和 body 标记中。

      【讨论】:

        猜你喜欢
        • 2013-06-09
        • 2012-02-05
        • 1970-01-01
        • 2015-02-11
        • 2015-04-12
        • 2012-10-30
        • 1970-01-01
        • 1970-01-01
        • 2019-05-22
        相关资源
        最近更新 更多