为什么萤火虫要加<tbody>到<表>? [英] Why does firebug add <tbody> to <table>?

查看:22
本文介绍了为什么萤火虫要加<tbody>到<表>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了 html 源代码,没有 ,但是在 HTML 选项卡中通过 firebug 查看时,出现 .知道为什么吗?

I viewed the html source code, there is no <tbody>, but when viewed via firebug in the HTML tab, <tbody> appears. Any idea why?

推荐答案

总结 bobince、Kieron、Alohci 和其他人在回答和评论中给出的出色解释:

To summarize the excellent explanations given in the answers and comments by bobince, Kieron, Alohci and others:

  1. Firebug 只显示已解析页面的 DOM.由于复杂的 HTML 解析规则,DOM 将与源 HTML不同"(在某种意义上).
  2. 在这种情况下,DOM 中的 TBODY 元素是由 HTML 解析器添加的.请注意,这种奇怪的解析仅限于 text/html 文档,并且在 XHTML 中,DOM 与源 XML 紧密对应.
    • 此行为已在 HTML 4.table 的内容模型(允许的孩子)是 (CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+) -- trs 只允许在 tbody 中!规范说 tbody 的开始标记是可选的,这应该意味着如果 HTML 解析器直接在 table 中遇到 tr 它插入作者省略的 tbody 开始标记.
    • 为了让事情更清楚,HTML 5 定义了 非常详细的解析规则,特别是对于这种情况:当插入模式为in table"时,必须按如下方式处理标记:[...] 标记名称为一的起始标记of: "td", "th", "tr" -> 就好像已经看到了标签名称为 "tbody" 的开始标记标记,然后重新处理当前标记."
  1. Firebug just displays the DOM of the parsed page. Due to complicated HTML parsing rules, the DOM will "differ" (in some sense) from the source HTML.
  2. In this case the TBODY element in the DOM is added by the HTML parser. Note that this weird parsing is limited to text/html documents and in XHTML the DOM corresponds closely to the source XML.
    • This behavior was specified in HTML 4. The content model (allowed children) for table is (CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+) -- trs are only allowed in tbody! The spec says that tbody's start tag is optional, which is supposed to mean that if the HTML parser encounters tr directly inside a table it inserts the tbody start tag omitted by the author.
    • To make matters more clear HTML 5 defines very detailed parsing rules, in particular for this case: "When the insertion mode is "in table", tokens must be handled as follows: [...] A start tag whose tag name is one of: "td", "th", "tr" -> Act as if a start tag token with the tag name "tbody" had been seen, then reprocess the current token."

这篇关于为什么萤火虫要加&lt;tbody&gt;到&lt;表&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆