为什么浏览器仍然注入< tbody>>在HTML5中? [英] Why do browsers still inject <tbody> in HTML5?

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

问题描述

HTML5 doctype示例



IE9和Chrome14日志< table> 中元素的 TBODY 作为 tagName c>



< table> 上的HTML5规范明确指出:


后跟零个或多个tbody元素或一个或多个tr元素

此外。 < tr> 明确指出:


作为table元素的子元素,在任何caption,colgroup和thead元素之后,但只有当没有tbody元素是表元素的子元素时才可以。


为什么浏览器会破坏我的DOM并注入一个 when




  • 我没有要求一个

  • 这是完全有效的,没有一个



  • 向后兼容的答案绝对是零的意义,因为我专门选择了一个HTML5文档类型。

    解决方案


    backwards compatiblity选择了HTML5文档类型。


    但是,浏览器不区分HTML版本。使用HTML5 doctype和HTML4 doctype的HTML文档(除了FPI中没有URL的HTML4过渡文档类型的小例外)被解析并以相同方式呈现。



    我会引用 HTML5解析器描述的相关部分


    8.2.5.4.9在表格中插入模式



    ...



    标签名称为td,th,tr之一的开始标签

    就好像标签名称为tbody的开始标记标记已被标记为
    ,然后重新处理当前标记。



    HTML5 doctype example.

    Both IE9 and Chrome14 log TBODY as the tagName of the element inside the <table>

    The HTML5 spec on <table> clearly states :

    followed by either zero or more tbody elements or one or more tr elements

    Furthermore. The HTML5 spec on <tr> clearly states :

    As a child of a table element, after any caption, colgroup, and thead elements, but only if there are no tbody elements that are children of the table element.

    Why are browsers corrupting my DOM and injecting a <tbody> when

    • I did not ask for one
    • It's perfectly valid without one

    The answer of "backwards compatiblity" makes absolutely zero sense because I specifically opted in for a HTML5 doctype.

    解决方案

    The answer of "backwards compatiblity" makes absolutely zero sense because I specifically opted in for a HTML5 doctype.

    However, browsers don't differentiate between versions of HTML. HTML documents with HTML5 doctype and with HTML4 doctype (with the small exception of HTML4 transitional doctype without URL in FPI) are parsed and rendered the same way.

    I'll quote the relevant part of HTML5 parser description:

    8.2.5.4.9 The "in table" insertion mode

    ...

    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;&gt;在HTML5中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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