javascript - 如何使用 AngularJS 添加不同的背景颜色

标签 javascript jquery html css angularjs

我想为表格设计格式中的 Angular ng-repeat 提供不同的背景颜色。如果 play_id 相同,我想在 tr 标签中提供相同的背景颜色,否则另一种颜色 tr 标签。

JSON ( https://jsfiddle.net/0sasz78n/ )

{
    "play_details": [
        {
            "play_id": "15",
            "quest_id": "63",
            "question": "What will be the match result ?"
        },
        {
            "play_id": "8",
            "quest_id": "61",
            "question": "Which of this batswan will score higher ?"
        },
        {
            "play_id": "8",
            "quest_id": "59",
            "question": "What will be the match result ?"
        }
    ]
}

HTML代码:

<table><tr ng-repeat="single_Play in all_Play_details">
    <td>{{$index + 1}}</td>
    <td>{{single_Play.play_id}}</td>
    <td>{{single_Play.quest_id}}</td>
    <td>{{single_Play.question}}</td>
</tr></table>

JS代码:

$scope.all_Play_details = response.data.play_details;

最佳答案

编辑:好的,Rouk 更快;)

我建议使用 ng-class 并在你的 ng-repeat 标签中添加类似下面的内容。

ng-class="{'highlightedCell' : play_details.play_id == currentID, 'diffentColoredCell' : play_details.play_id != currentID"}

当然还要创建适当的 css 类。

关于javascript - 如何使用 AngularJS 添加不同的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41425358/

相关文章:

java - 要下载哪个插件才能在 google chrome 上显示 java applet

javascript - 只显示 map 后悬停的项目

javascript - 我可以在 Vue.js 中使用 CSS 函数绑定(bind)内联样式吗? Vue.js 假设 translate3d() 是一个 JavaScript 函数,并表示它没有定义

javascript - Highland.js、Kefir.js 和 Rx.js 之间的区别是什么?

php - 使用 PHP 和 jQuery 更改 CSS 样式

javascript - 我怎样才能只附加一次?

javascript - 使用 JQuery/Javascript 显示复选框格式选项的实时预览

javascript - 具有普通概念javascript的自动完成文本框

javascript - 如何将一行中的所有数据复制到所有其他行

html - 如何在几乎不支持 javascript 的老式移动浏览器上像使用 CSS 那样很好地降级 HTML5?