gpt4 book ai didi

php - 根据值更改 td 类?

转载 作者:太空宇宙 更新时间:2023-11-03 21:08:41 25 4
gpt4 key购买 nike

我在表格中有几行,我想根据值更改某些元素的类。我现在拥有的:

<td><span class="label label-warning">".$rows["riskScoreText"]."</span></td>
  • 如果“riskScoreText”的值为“高”,它应该具有标签警告类。
  • 如果“riskScoreText”的值为“Low”,它应该具有标签成功类。

我将如何做到这一点?

最佳答案

试试这个:

$value = $rows["riskScoreText"];

if($value == 'High') {
$class = "label label-warning";
} else {
$class = "label label-low"; }

<td><span class="<?php echo $class>">".$rows["riskScoreText"]."</span></td>

当然,如果你有两个以上的类,你可以使用elseif语句添加它们。

关于php - 根据值更改 td 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49438477/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com