【问题标题】:How to change the text color based on a value using php and html?如何使用 php 和 html 根据值更改文本颜色?
【发布时间】:2019-09-02 11:54:59
【问题描述】:

我有 2 个值 $minsRecoded 和 $totalMins,我想如果 minsRecorded 大于 totalMins 然后在危险徽章中显示 $totalMinsComplted。

这是我的控制器中的内容

$sumMins = \App\ProjectTimeLog::where('user_id', '=', '1')->pluck('total_minutes')->sum()/60;
  $minsRecoded = Task::getTotalMinsCompleted()/60;


  $totalMin = \App\ProjectTimeLog::where('user_id', '=', '1')->pluck('total_minutes')->sum()/60;
  $this->totalMins = \App\ProjectTimeLog::where('user_id', '=', '1')->pluck('total_minutes')->sum()/60;

if ($minsRecoded < $totalMin) $this->totalMinsCompleted = '<span class="badge badge-danger">";

这是我的看法

 {{$totalMinsCompleted}}/{{$totalMins}}

【问题讨论】:

    标签: php html laravel-5


    【解决方案1】:

    使用.= 连接徽章。当 if 条件为真时,这将保留原始内容并附加标记。

    if ($minsRecoded < $totalMin) $this->totalMinsCompleted .= '<span class="badge badge-danger">';
    

    【讨论】:

    • 对于默认徽章或其他东西,您可以像这样连接 totalMinsCompleted $this->totalMinsCompleted .= ($minsRecoded ' : '';
    猜你喜欢
    • 2017-08-01
    • 2017-08-01
    • 2015-11-18
    • 2014-07-16
    • 2017-08-15
    • 2017-03-09
    • 1970-01-01
    • 1970-01-01
    • 2021-09-14
    相关资源
    最近更新 更多