我有一个名为weather的数据库表,该表具有以下数据:
Place Temperature
Delhi 30
Bangalore 35
Hyderabad 45
Mumbai 41
现在,我使用php获取这些数据,并在表中将其查看给客户端。
现在我的问题是如何根据值(即温度)动态更改行字体颜色。我必须使用javascript将函数放在服务器端还是客户端。
我已经以这种方式应用了逻辑,但尚未到达目的地。
//here is my logic that i have put in my php file while fetching the data
if (row["Temperature"] > row["MaxTemperature"]){
this.getStyle().color= "red"; }
else{
this.getStyle().color="yellow";}
//I have set a value for MaximumTemperate
我可以通过创建几个CSS类来做到这一点,即:
<style>
.red_temperature {
color: red;
}
.yellow_temperature {
color:yellow;
}
</style>
然后在您的php中,当您生成客户端代码时,您将该类添加到div的class =“”中,其中包含要向客户端显示的值。
即:
<?php
// set $classColor variable here based on mysql row
...
echo "<div class='".$classColor."'>74</div>"; // where $classColor = 'yellow_temperature'
?>
这只是一般的起点,而不是最终的代码,而只是试图以正确的思路将您指向正确的方向。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句