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

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

问题描述

我正在使用原始html和JQuery来玩弄一些想法。我做的一件事是创建一个包含一组行的表元素。

 < table id =MyTable> 
< tr>
< td>标题< / 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 ...所有人都显示了围绕所有 tr 节点的 tbody 元素。



I 'm不反对这种情况发生......但这是标准行为吗?

.com / reference / html40 / tables / tbody.htmlrel =noreferrer> http://htmlhelp.com/reference/html40/tables/tbody.html :


TBODY元素在表中定义一组数据行。一个TABLE必须有一个或多个TBODY元素,它必须遵循可选的TFOOT。 TBODY结束标签始终是可选的。如果表中只包含一个TBODY,并且没有THEAD或TFOOT,则开始标记是可选的。


所以总会有一个tbody(尽管有时候开始和结束标签都是可选和省略的),并且您使用的工具在向您显示时是正确的。



thead或tfoot,另一方面,除非你明确包含它们,否则永远不会存在,如果你这样做了,那么tbody也必须是明确的。


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>

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:

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.

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

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天全站免登陆