dongtang3155 2018-06-08 08:55
浏览 745
已采纳

我想根据条件更改文本颜色

I am trying to show the text color change dynamically based on the condition that i am using in the code.Below is the code that i am using.Please help me out from this problem.

<span class="pendtext" style="font-size:15px;">{{($duepay->status == 'issued') ? 'PENDING' : (($duepay->status == 'paid') ? 'SUCCESSFUL' : $duepay->status)}}</span>


<script>

if($duepay->status == 'issued'){
  $(".pendtext").css('color','green');
}
else{
  $(".pendtext").css('color','yellow');
}

</script>
  • 写回答

3条回答 默认 最新

  • doushan1850 2018-06-08 09:03
    关注

    Why use a JS if you work with PHP? you can do with PHP too like

    <span class="pendtext" style="font-size:15px;color:{{($duepay->status == 'issued')?'green':'yellow'}}">{{($duepay->status == 'issued') ? 'PENDING' : (($duepay->status == 'paid') ? 'SUCCESSFUL' : $duepay->status)}}</span>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?