为什么浏览器会在表格元素中插入 tbody 元素? [英] Why do browsers insert tbody element into table elements?

查看:85
本文介绍了为什么浏览器会在表格元素中插入 tbody 元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用原始 html 和 JQuery 的一些想法.我做的一件事是创建一个包含一组行的表格元素.

I was playing around with some ideas using raw html and JQuery. One thing I did was to create an table element with a set of rows.

<table id="MyTable" >
    <tr>
        <td>Title</td>
    </tr>
    <tr>
        <td>1</td>
    </tr>
    <tr>
        <td>2</td>
    </tr>
    <tr>
        <td>3</td>
    </tr>
    <tr>
        <td>4</td>
    </tr>
</table>

但是当我在 FireFox+Firebug、IE8 Developer Toolbar 或 Google Chrome JavaScript Debugger 中查看代码时……所有这些都显示有一个 tbody 元素围绕着所有 >tr 节点.

But when I viewed the code in FireFox+Firebug, IE8 Developer Toolbar, or the Google Chrome JavaScript Debugger...all of them showed there to be a tbody element surrounding all of the tr nodes.

我不反对这种情况发生……但这是标准行为吗?

I'm not against this happening...but is this standard behavior?

推荐答案

http://htmlhelp.com/reference/html40/tables/tbody.html:

TBODY 元素定义了表格中的一组数据行.一个 TABLE 必须有一个或多个 TBODY 元素,这些元素必须跟在可选的 TFOOT 之后.TBODY 结束标记始终是可选的.当表只包含一个 TBODY 而没有 THEAD 或 TFOOT 时,开始标记是可选的.

The TBODY element defines a group of data rows in a table. A TABLE must have one or more TBODY elements, which must follow the optional TFOOT. The TBODY end tag is always optional. The start tag is optional when the table contains only one TBODY and no THEAD or TFOOT.

所以那里总是有一个 tbody(尽管有时开始和结束标签都是可选的和省略的),并且您使用的工具向您展示它是正确的.

So there always is a tbody there (albeit sometimes with both the start and end tags optional and omitted), and the tools you are using are correct in showing it to you.

另一方面,thead 或 tfoot 永远不会出现,除非您明确包含它们,如果您这样做,tbody(s) 也必须是明确的.

thead or tfoot, on the other hand, are never present unless you explicitly include them, and if you do that, the tbody(s) must be explicit too.

这篇关于为什么浏览器会在表格元素中插入 tbody 元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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