我可以更改< td>如果字段结果大于或等于另一个字段,则为背景? [英] Can I change the <td> background if a field result is great or equal to another field?
本文介绍了我可以更改< td>如果字段结果大于或等于另一个字段,则为背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在html表中显示mySQL。
I am displaying mySQL in an html table.
我想将$ qty的TD背景颜色更改为红色 IF $ qty > = $ max或$ qty =< $ min
。
I would like to change the TD background color of $qty to red IF $qty >= $max or $qty =< $min
.
使用jQuery或PHP有一种简单的方法吗?
Is there a simple a way to do this with jQuery or PHP?
我为我的例子简化了我的表格和PHP:
I simplified my table and PHP for my example:
<table id="tablesorter-demo">
<tr><td>'.$min.'</td><td>'.$max.'</td><td>'.$qty.'</td></tr>
</table>
推荐答案
var min = $('table tr td:eq(0)').text();
var max = $('table tr td:eq(1)').text();
var qty = $('table tr td:eq(2)').text();
if (qty >= max || qty <= min ) {
$('table tr td:eq(2)').css('background-color', 'red');
}
这篇关于我可以更改< td>如果字段结果大于或等于另一个字段,则为背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文