0

我认为有两张桌子;试图改变一个表中交替行的背景。在我使用的样式文件中:

 .alternateRow
{
    table-layout: auto;
    border-collapse: collapse;
    border-spacing: 0px;
    empty-cells: hide;
}

.alternateRow tr {
     background-color:#aa0000;

}

.alternateRow tr.odd  {
     background-color:#00AA00;

}

这就是我制作动态表的方式:

<table class="alternateRow">
        <% List<Question> wrongs = ViewBag.wrongs;
       for (var i = 0; i < wrongs.Count; ++i)
       { %>
        <tr>
            <td>
                <%= wrongs[i].TheQuestion %>
            </td>
            <td>
                Correct Answer
            </td>
            <td>
                <%= wrongs[i].CorrectAnswer %>
            </td>
            <td>
                <%= wrongs[i].Explanations %>
            </td>
        </tr>
        <% } %>

我没有工作,两行颜色相同。知道我做错了什么吗?

4

1 回答 1

0

这是您可以执行的操作:

<% List<Question> wrongs = ViewBag.wrongs;
for (var i = 0; i < wrongs.Count; ++i)
{ 
    var rowClass = ((i % 2) == 0 ? "" : "odd"); // or whatever your alternate row class is
%>
    <tr class="<%= rowClass %>">
        <td>
            <%= wrongs[i].TheQuestion %>
        </td>
        <td>
            Correct Answer
        </td>
        <td>
            <%= wrongs[i].CorrectAnswer %>
        </td>
        <td>
            <%= wrongs[i].Explanations %>
        </td>
    </tr>
<% } %>
于 2013-08-24T22:12:58.673 回答