浏览器如何分析 <tr><td>没有<table>? [英] How do browsers analyze <tr> <td> without <table>?

查看:27
本文介绍了浏览器如何分析 <tr><td>没有<table>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<table border="1">
    <tbody>
        <tr>
            <td>1</td>
            <td>2</td>
        </tr>
        <tr>
            <td>3</td>
            <td>4</td>
        </tr>
    </tbody>
</table>

如果我这样写,浏览器会正常分析.

If I write this, the browser will analyze normally.

<!-- <table border="1"> -->
    <tbody>
        <tr>
            <td>1</td>
            <td>2</td>
        </tr>
        <tr>
            <td>3</td>
            <td>4</td>
        </tr>
    </tbody>
<!-- </table> -->

但我是这样写的,我发现浏览器会分析它们,没有任何像字符串这样的标签.

But I write like this, I find the browser will analyze them without any tags like string.

<tbody>
    <tr>
        <td>1</td>
        <td>2</td>
    </tr>
    <tr>
        <td>3</td>
        <td>4</td>
    </tr>
</tbody>

1 2 3 4

推荐答案

浏览器忽略 <;td> 标签和相应的结束标签.这在 HTML 规范中没有指定,因为它们没有定义语法错误文档的解析.然而,在 HTML5 草案中,有一个描述以对应于浏览器实际操作的方式定义浏览器行为:树结构.

Browsers ignore the <tbody>, <tr>, and <td> tags and the corresponding end tags. This has not been specified in HTML specifications, since they do not define the parsing of syntactically erroneous documents. In the HTML5 draft, however, there is a description that defines the browser behavior in a manner that corresponds to the what browsers actually do: Tree construction.

这意味着您不能编写一个 HTML 文档,例如在 table 元素之外包含一个 <tr> 元素.浏览器中的 HTML 解析器根本不会构造这样的文档树.(但是,您可以使用客户端描述动态构建这样的文档.)

This means that you cannot write an HTML document that contains, say, a <tr> element outside a table element. The HTML parser in a browser simply does not construct such document trees. (You can, however, construct such a document dynamically with client-side scription.)

这篇关于浏览器如何分析 &lt;tr&gt;&lt;td&gt;没有&lt;table&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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