[英]Styling output in ternary operator
how to put color the in output of ternary operator.如何在三元运算符的 output 中放置颜色。
I would like to do if false it should be black if true it should be red如果为假,我想做它应该是黑色的,如果为真,它应该是红色的
this is my code:这是我的代码:
'<td>' .($totalStocks < $minimumStockLevel ? 'true': 'false'). '</td>' .
You need some CSS, and then add an appropriate class to your data:您需要一些 CSS,然后将适当的 class 添加到您的数据中:
<style>
.redCell {color:red;}
.blackCell {color:black;}
</style>
Then your code becomes:然后你的代码变成:
'<td class="'.($totalStocks < $minimumStockLevel ? 'redCell': 'blackCell').'">' .$someValue. '</td>' .
This should generate something like this:这应该生成如下内容:
<td class="redCell">someValue</td>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.