本文介绍了我们可以有多个< tbody>在相同的< table>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以在同一个< table> 中有多个< tbody> 如果是,那么在什么情况下我们应该使用多个< tbody> 标签?

Can we have multiple <tbody> tags in same <table>? If yes then in what scenarios should we use multiple <tbody> tags?

推荐答案

是的,你可以使用它们,例如我使用它们更容易地对数据组进行风格化,例如:

Yes you can use them, for example I use them to more easily style groups of data, like this:

<table>
    <thead>
        <tr><th>Customer</th><th>Order</th><th>Month</th></tr>
    </thead>
    <tbody>
        <tr><td>Customer 1</td><td>#1</td><td>January</td></tr>
        <tr><td>Customer 1</td><td>#2</td><td>April</td></tr>
        <tr><td>Customer 1</td><td>#3</td><td>March</td></tr>
    </tbody>
    <tbody>
        <tr><td>Customer 2</td><td>#1</td><td>January</td></tr>
        <tr><td>Customer 2</td><td>#2</td><td>April</td></tr>
        <tr><td>Customer 2</td><td>#3</td><td>March</td></tr>
    </tbody>
    <tbody>
        <tr><td>Customer 3</td><td>#1</td><td>January</td></tr>
        <tr><td>Customer 3</td><td>#2</td><td>April</td></tr>
        <tr><td>Customer 3</td><td>#3</td><td>March</td></tr>
    </tbody>
</table>

然后,您可以轻松地对它们进行风格设置,例如:

Then you can style them easily, like this:

tbody:nth-child(odd) { background: #f5f5f5; }
tbody:nth-child(even) { background: #e5e5e5; }

,它只会在较新的浏览器中工作...但这是我在我当前的应用程序支持,你可以使用分组JavaScript等。主要的是它是一种方便的方式来可视地分组行,使数据更加可读。当然还有其他用途,但就适用的例子而言,这一个是我最常见的一个。

You can view an example here, it'll only work in newer browsers...but that's what I'm supporting in my current application, you can use the grouping for JavaScript etc. The main thing is it's a convenient way to visually group the rows to make the data much more readable. There are other uses of course, but as far as applicable examples, this one is the most common one for me.

这篇关于我们可以有多个&lt; tbody&gt;在相同的&lt; table&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 02:39