繁体   English   中英

如何根据对象的值设置跨度的类?

[英]How can I set the class of a span based on the value of an object?

这是我的代码:

<span class="msg" data-ng-show="question.message == 'Correct'" style="color: green;">Correct</span>
<span class="msg" data-ng-show="question.message == 'Incorrect'" style="color: red;">Incorrect</span>
<span class="msg" data-ng-show="question.message == 'Answers Shown'">Answers Shown</span>

有没有办法可以将课程设置为“红色”或“绿色”或什么都没有,所以我可以将这三行合并为一个?

看看ng-class你可以在ng-show中使用任何表达来计算类名

也许:

<style>
 .Correct{
  color: green; 
 }
 .Incorrect{
  color: red; 
 }
</style>

<span class="msg {{question.message}}" >{{question.message}}</span>

示例: http//jsfiddle.net/cherniv/fYFJp/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM