Html 表中的多个 <thead>/<tbody> 是否有效?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16155396/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 07:46:14  来源:igfitidea点击:

Multiple <thead>/ <tbody> in Table Valid?

javascripthtml

提问by AlbertEngelB

Imagine a list of lists similar to this:

想象一个类似这样的列表:

var list = [
  { name: 'group1', 
    items: [ 1, 2, 3, 4, 5 ]
  },
  { name: 'group2', 
    items: [ 1, 2, 3, 4, 5 ]
  },
  etc...
]

Now forgetting the whole "tables are for data not design" argument, I wanted to display a single table for listand have a seperate <thead>and <tbody>for each entry in list.

现在忘记了整个“表数据没有设计”的说法,我想显示一个表list,并有一个单独的<thead>,并<tbody>在每个条目list

Is this technically valid? This works in the browser, but my spider senses are tingling on this one.

这在技术上有效吗?这在浏览器中有效,但我的蜘蛛感觉对这个感到刺痛

回答by Jon

You can have as many <tbody>elements as you want, but no more than one each of <thead>and <tfoot>. Reference:

您可以拥有任意数量的<tbody>元素,但<thead>和 中的每个元素不超过一个<tfoot>参考

Content model:

In this order: optionally a caption element, followed by zero or more colgroup elements, followed optionally by a thead element, followed by either zero or more tbody elements or one or more tr elements, followed optionally by a tfoot element, optionally intermixed with one or more script-supporting elements.

内容模型:

按此顺序:可选的标题元素,后跟零个或多个 colgroup 元素,可选地后跟一个 thead 元素,后跟零个或多个 tbody 元素或一个或多个 tr 元素,后跟可选的 tfoot 元素,可选地与一个混合或更多脚本支持元素。

回答by Zeta

There's at most one theadand one tfootallowed, so you shouldn't create additional headers. After all the thin a theadgives a meaning to your columns, like "time of day", "temperature", "amount of cats currently on fire".

最多有一个thead和一个tfootallowed,所以你不应该创建额外的标题。毕竟thin athead为您的列赋予了含义,例如“一天中的时间”、“温度”、“当前着火的猫数量”。

If the entries in your list are related they should all be in the same table and you should provide a fitting header to display that relation.

如果列表中的条目相关,它们应该都在同一个表中,并且您应该提供一个合适的标题来显示该关系。

If the entries are actually unrelated you should provide a single table for every of those. You can still apply the same CSS on every table to get a nice result.

如果条目实际上不相关,您应该为每个条目提供一个表格。您仍然可以在每个表上应用相同的 CSS 以获得不错的结果。

回答by Justin

I consider it to be just like idattributes. They are supposed to be unique, but you can actually re-use it in the same page and you can still select it. That said, just because it can be done doesn't mean it should be done.

我认为它就像id属性一样。它们应该是独一无二的,但您实际上可以在同一页面中重复使用它,并且您仍然可以选择它。 也就是说,仅仅因为它可以完成并不意味着它应该被完成。

I would recommend against it.

我会建议反对它。