gpt4 book ai didi

javascript - 带有 ng-repeat 的 html 表中的替代行着色

转载 作者:太空宇宙 更新时间:2023-11-03 20:31:51 24 4
gpt4 key购买 nike

我有一个表格,其中使用 ng-repeat 填充了值。我需要用绿色和黄色交替为表格的行着色。我在没有 ng-repeat 的情况下通过以下方式尝试了它并且它有效。

.table-striped>tbody>tr:nth-of-type(odd)
{
background: yellow !important;
}

.table-striped>tbody>tr:nth-of-type(even)
{
background: green !important;
}
<html>
<div><table class="table table-striped">
<thead style="border: 1px solid">
<tr>
<th>Heading</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{value.val1}}</td>
</tr>
<tr>
<td>{{value.val2}}</td>
</tr>
<tr>
<td>{{value.val3}}</td>
</tr>
</tbody>
</table>
</div>
<html>

但它在使用 ng-repeat 时不起作用,如下所示(所有行本身都是黄色的)。请帮助。提前致谢。

.table-striped>tbody>tr:nth-of-type(odd)
{
background: yellow !important;
}

.table-striped>tbody>tr:nth-of-type(even)
{
background: green !important;
}
<html>
<div><table class="table table-striped">
<thead style="border: 1px solid">
<tr>
<th>Heading</th>
</tr>
</thead>
<tbody ng-repeat="value in values">
<tr>
<td>{{value.val1}}</td>
</tr>

</tbody>
</table>
</div>
<html>

最佳答案

我觉得你应该给ng-repeat="value in values"尽量不要tbody。你在 body 上 ng-repeat 会重复 body 元素。

关于javascript - 带有 ng-repeat 的 html 表中的替代行着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40543929/

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