着色负数/正数(jQuery) [英] Colorize negative/positive numbers (jQuery)

查看:460
本文介绍了着色负数/正数(jQuery)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为表格中的数字添加颜色以提高可读性:

I'd like to color numbers in a table for better readability: 

绿色表示正(+00.00);
为红色(-00.00)和;
默认情况下黑色(无符号)

green for positive (+00.00); red for negative (-00.00) and; black for default case (no sign)

非常感谢!

推荐答案

这里ya go:

Here ya go:

$(document).ready( function() {

  // the following will select all 'td' elements with class "of_number_to_be_evaluated"
  // if the TD element has a '-', it will assign a 'red' class, and do the same for green.

  $("td.of_number_to_be_evaluated:contains('-')").addClass('red');
  $("td.of_number_to_be_evaluated:contains('+')").addClass('green');
}

然后使用CSS对输入元素:

Then use CSS to style the input elements:

td.red {
  color: red;
}

td.green {
  color: green;
}

这篇关于着色负数/正数(jQuery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆