【发布时间】:2016-05-09 14:10:51
【问题描述】:
下面有html,
<em>+5.0</em>
<em>+3.2</em>
<em>-2.4</em>
<em>-4.6</em>
我想根据条件为每个数字设置颜色。 如果数字大于 0,颜色将为红色。 其他人会是蓝色的。输出将是
+5.0 (red color)
+3.2 (red color)
-2.4 (blue color)
-4.6 (blue color)
如何用 jQuery 做到这一点?
我尝试了什么
if ($('em').text() > 0){
$(this).css('color', 'red');
}
但$('em').text() 不是一个元素,我无法正确应用样式。
我该怎么做?
【问题讨论】:
标签: javascript jquery