HTML / CSS / JavaScript:如何根据数据更改表格行的颜色

时间:2016-03-04 15:59:09

标签: javascript jquery html css angularjs

首先,我知道这可能是重复的,但我尝试了其他解决方案,但没有任何工作。无论如何,我有一个HTML表格:

class A {
public:
    const int NUM_A = 1;

    A() :
        b(NUM_A)
    {
        std::cout << "A's number: " << NUM_A << std::endl;
    }

private:
    const int NUM_A = 1;
    B b;    

    //B b;    
    //const int NUM_A = 1;
};

所以排名可以是<table class="table1"> <tr> <th>Rank</th> <th>Name</th> <th>Picture</th> <th>Serial Number</th> </tr> <tbody class="tbody" > <tr class="bodyrow" ng-repeat="item in rank track by $index"> <td>{{item}}</td> <td>{{name[$index]}}</td> <td> <img ng-src="{{img[$index]}}"/></td> <td>{{serialNumber[$index]}}</td> </tr> </tbody> </table> BasicMiddle。如果等级为Advanced,那么该条目的整行应为蓝色。如果排名为Basic,则该条目的行应为黄色,Middle应使该行为绿色。请帮忙吗?

1 个答案:

答案 0 :(得分:0)

标记(假设{{item}}具有等级名称):

<table class="table1">
    <tr>
        <th>Rank</th>
        <th>Name</th>
        <th>Picture</th>
        <th>Serial Number</th>
    </tr>
    <tbody class="tbody" >
        <tr class="bodyrow" ng-class="item" ng-repeat="item in rank track by $index">
            <td>{{item}}</td>
            <td>{{name[$index]}}</td>
            <td> <img ng-src="{{img[$index]}}"/></td>
            <td>{{serialNumber[$index]}}</td>
        </tr>
    </tbody>

</table>

样式:

.basic{background: blue}
.middle{background: yellow}
.advanced{background: green}