gpt4 book ai didi

javascript - 选择表格中的每 4 行

转载 作者:太空宇宙 更新时间:2023-11-04 02:35:29 26 4
gpt4 key购买 nike

有没有一种方法可以让我在表格中选择 4 行并将其背景设置为红色,然后选择接下来的 4 行并将其背景设置为蓝色?它有点像奇数和偶数,但以不同的方式选择了一组行。有什么想法、帮助、建议、线索、建议吗?

<table>
<!--- odd -->
<tr>
<td>NAME</td><td>AGE</td>
</tr>
<tr>
<td>NAME</td><td>AGE</td>
</tr>
<tr>
<td>NAME</td><td>AGE</td>
</tr>
<tr>
<td>NAME</td><td>AGE</td>
</tr>
<!--- even -->
<tr>
<td>NAME</td><td>AGE</td>
</tr>
<tr>
<td>NAME</td><td>AGE</td>
</tr>
<tr>
<td>NAME</td><td>AGE</td>
</tr>
<tr>
<td>NAME</td><td>AGE</td>
</tr>
<!--- odd -->
<tr>
<td>NAME</td><td>AGE</td>
</tr>
<tr>
<td>NAME</td><td>AGE</td>
</tr>
<tr>
<td>NAME</td><td>AGE</td>
</tr>
<tr>
<td>NAME</td><td>AGE</td>
</tr>
</table>

最佳答案

如果您正在寻找纯 css 解决方案,您可以这样做:

table tr:nth-of-type(n) {

background: blue;

}

table tr:nth-of-type(8n),

table tr:nth-of-type(8n-1),

table tr:nth-of-type(8n-2),

table tr:nth-of-type(8n-3) {

background: red;

}
<table>
<!--- odd -->
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<!--- even -->
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<!--- odd -->
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr>
<td>NAME</td>
<td>AGE</td>
</tr>
</table>

关于javascript - 选择表格中的每 4 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35737973/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com