HTML表格浏览器呈现问题 [英] HTML table browser render issues
问题描述
a.考虑以下标记:
<table><th></th></table>
当我检查页面时,我得到:
When i inspect the page i get:
<body><table><tbody><tr><th></th></tr></tbody></table>
b.考虑以下标记:
<table><span role="columnheader"></span></table>
当我检查页面时,我得到:
When i inspect the page i get:
<body><span role="columnheader"></span><table></table>
- 在chrome,ff和资源管理器(11)上进行了测试.
怎么可能?
在尝试测试parentNode
时,我遇到了这种情况,并且在两种情况下都没有获得表".
I ran this situation while i tried to test the parentNode
and didn't got "table" on both scenarios as expected.
有人可以掩盖这种行为吗?
Can someone please shade light on this behavior?
推荐答案
这两组HTML均无效,并且浏览器正在执行错误恢复.恢复规则(或常规解析器规则)在表元素内部的跨度与在表元素内部的th的恢复规则不同.
Both sets of HTML are invalid and the browser is performing error recovery. The recovery rules (or rather, the general parser rules) for a span inside a table element are different to the recovery rules for a th inside a table element.
(为简化起见,第一个元素必须位于表中tbody/tfoot/thead内的tr内……因此添加了丢失的元素,但跨度根本不必位于表内,因此扔掉).
(To oversimplify, a th element has to be inside a tr inside a tbody/tfoot/thead inside a table … so the missing elements are added, but a span doesn't have to be inside a table at all so is thrown out).
您应该从一开始就编写有效的HTML.
You should just write valid HTML from the outset.
这篇关于HTML表格浏览器呈现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!