有人可以提供一种快速替代方法来让 jquery 显示具有不同背景颜色的交替行吗?尝试使用 foreach 循环但运气不佳。非常感谢!!!
<div class="acgridhdrstart">Account Name</div>
<div class="acgridhdr">Account Region</div>
<div class="acgridhdr">Account Representative</div>
<div class="acgridhdr">Peer Partner</div>
<div class="acgridhdr">Last Updated</div>
@while (myreader.Read())
{
<div class="bgcol">
<span class="acgridstart">@myreader["acname"]</span>
<span class="acgrid">@myreader["acregion"]</span>
<span class="acgrid">@myreader["acrep"]</span>
<span class="acgrid">@myreader["acpeer"]</span>
<span class="acgrid">@myreader["lastupdated"]</span>
</div>
}
最佳答案
使用 CSS3 你可以 :nth-child(even) 和 :nth-child(odd)
http://www.w3.org/TR/css3-selectors/#nth-child-pseudo
jQuery 版本,FWIW:
http://api.jquery.com/nth-child-selector/
如果你想在 View 代码中使用它,Phil Haack 的 Cycle 方法可能会有用
http://haacked.com/archive/2008/08/07/aspnetmvc_cycle.aspx
如果你不知道,WebGrid 有 rowStyle 和 alternatingRowStyle
http://msdn.microsoft.com/en-us/magazine/hh288075.aspx
http://msdn.microsoft.com/en-us/library/system.web.helpers.webgrid.gethtml(v=vs.99).aspx
关于c# - 在数据网格中显示交替行颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9049988/