dongliang7545 2016-05-19 23:03
浏览 494

根据td值更改文本颜色

I have a table that returns values from my Mysql database without issue. What I want to do is change the font color to green if two of the five values is selected from radio buttons.

The field that I wish to change the color is the "Category" field if the value is either Vegetarian or Vegan. All other options will be the default color (black).

This is my code that displays the table data, which is displaying as I wish:

$richOutput = widgets\RichText::widget(['text' => $post->message,     'record' => $post]);
$richOutput_rname = widgets\RichText::widget(['text' => $post->rname, 'record' => $post]);
$richOutput_category = widgets\RichText::widget(['text' => $post->category, 'record' => $post]); ?>
<table>
<tr><td><span id="post-content-<?php echo $post->id; ?>" <?php print $richOutput; ?></span></font></td></tr>
<tr><td><span id="post-content-rname-<?php echo $post->id; ?>" <?php print $richOutput_rname; ?></span></td></tr>
<tr><td><span id="post-content-category-<?php echo $post->id; ?>" <?php print $richOutput_category; ?></span></td></tr>
</table>

Thank you in advance!

Edit

I tried to add the following JS, but it did not change the text color when the value = "Vegan":

    <script type="text/javascript">
$('.cat').each(function(i, n) {
   if($(n).text() = "Vegan") $(n).css('color', '#8A1010');
});
</script>
  • 写回答

2条回答 默认 最新

  • dqwr32867 2016-05-19 23:54
    关注

    I didn't test this, but it should be correct. You should get the idea.

     <tr><td><span id="post-content-category-<?php echo $post->id; ?>" <?php $richOutput_category == "Vegan" ? echo 'style="color: #8A1010"' : echo '' ?>><?php print $richOutput_category; ?></span></td></tr>
    

    Also you were missing a '>' on the span tag (all of them).

    评论

报告相同问题?

悬赏问题

  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止