dongzhong5833 2012-05-26 00:37 采纳率: 0%
浏览 17
已采纳

通过条件> =或<=在2个数字字段之间更改TD背景颜色[重复]

Possible Duplicate:
Can I change the <td> background if a field result is great or equal to another field?

Trying to get my script to work, displaying mySQl results in an HTML table via php with a particular column TD that contains $qty that needs to have its background turn red when it equals or passes $min or $max.

Maybe there's a better way to right this php?

Script is not working.

<script type="text/javascript">
$(document).ready(function() {
var min = parseInt($('.min').text());
var max = parseInt($('.max').text());
var qty = parseInt($('.quantity').text());

if (qty >= max || qty <= min ) {
$('.quantity').css('background-color', 'red');
} 
});
</script>

My php table / the three fields are toward the end of the table:

$o .= '<tr><td>'.$type.'</td><td>'.$part_no.'</td><td>'.$description.'</td><td>'.$artwork.' &nbsp; &nbsp;</td><td><a href="/data/hero/copies/'.$part_no.'.pdf" target="_blank">Link &nbsp;</a></td><td align=right class="min">'.number_format($min).'</td><td align=right class="max">'.number_format($max).'</td><td align=right class="quantity">'.number_format($qty).'</td></tr>';}
  • 写回答

1条回答 默认 最新

  • dongyinting3179 2012-05-26 00:51
    关注

    Your php sample has a stray } at the end of the line. Is that causing this issue?

    I've just tried this with the javascript you posted and this php:

    $o = '<tr><td>'.$type.'</td><td>'.$part_no.'</td><td>'.$description.'</td><td>'.$artwork.' &nbsp; &nbsp;</td><td><a href="/data/hero/copies/'.$part_no.'.pdf" target="_blank">Link &nbsp;</a></td><td align=right class="min">'.number_format($min).'</td><td align=right class="max">'.number_format($max).'</td><td align=right class="quantity">'.number_format($qty).'</td></tr>';
    

    It works perfectly.

    Is $o getting properly printed out to the browser? If you view the HTML source, do you have a tds with the classes min, max and quantity? What exact symptoms of it not working do you get? Maybe you could post a little more of the script?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100