<tbody>标签显示在 chrome 中,但不是源代码 [英] &lt;tbody&gt; tag displays in chrome but not source

查看:26
本文介绍了<tbody>标签显示在 chrome 中,但不是源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在做一些抓取工作时,我一直在 Chrome DevTools 检查器中遇到 标记,但它没有出现在源代码中.由于我希望是显而易见的原因,我觉得这非常令人困惑.这里发生了什么?(我还应该补充一点,此页面上的 html 格式非常错误).

In doing some scraping work I keep encountering the <tbody> tag in the Chrome DevTools inspector, but it doesn't appear in the source. For what I hope are obvious reasons, I find this super confusing. What's going on here? (I should also add that the html on this page is pretty malformed).

例如,DevTools 显示:

For example, DevTools shows:

<table>
    <tbody>
        <tr valign="top">
            <td>...</td>

页面源显示:

<table border="0">
    <tr valign="top">
        <td>

推荐答案

的开始标记是可选的.也就是说,您可以将其省略,但浏览器会在需要时自动插入.

The start tag for <tbody> is optional. That is, you can leave it out, but it is automatically inserted by the browser whenever needed.

需要的,因为规则说你不能在table中直接有tr.table 元素的唯一子元素可以是 captioncolgrouptheadtbody> 和 tfoot.
因此,如果浏览器在 tbody 之外遇到 tr,它会插入一个 tbodytr 将驻留在其中.

And it is needed, because the rules say you can't have a tr directly in a table. The only children of a table element can be caption, colgroup, thead, tbody and tfoot.
So, if the browser encounters a tr outside a tbody, it inserts a tbody which the tr will reside in.

有关更正式的表述方式,请参见 http://www.w3.org/TR/html-markup/tbody.html

For a more formal way of saying this, see http://www.w3.org/TR/html-markup/tbody.html

顺便说一下,同样的情况发生在其他开始标签上,比如 .如果你忽略它,比如在 </head> 之后直接写一个

,浏览器将插入一个隐含的 ; 自动.

By the way, the very same happens with other start tags, like <body>. If you omit that, writin, say, a <h1> directly after the </head>, the browser will insert an implied <body> automatically.

这篇关于<tbody>标签显示在 chrome 中,但不是源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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