问题描述
我查看了 html 源代码,没有 I viewed the html source code, there is no 总结 bobince、Kieron、Alohci 和其他人在回答和评论中给出的出色解释: To summarize the excellent explanations given in the answers and comments by bobince, Kieron, Alohci and others: 这篇关于为什么萤火虫要加<tbody>到<表>?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!,但是在 HTML 选项卡中通过 firebug 查看时,出现
.知道为什么吗?
<tbody>
, but when viewed via firebug in the HTML tab, <tbody>
appears. Any idea why?推荐答案
TBODY
元素是由 HTML 解析器添加的.请注意,这种奇怪的解析仅限于 text/html 文档,并且在 XHTML 中,DOM 与源 XML 紧密对应.table
的内容模型(允许的孩子)是 (CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+)
-- tr
s 只允许在 tbody
中!规范说 tbody
的开始标记是可选的,这应该意味着如果 HTML 解析器直接在 table
中遇到 tr
它插入作者省略的 tbody
开始标记.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.table
is (CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+)
-- tr
s 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.