我需要根据以下内容写出绿色或红色的文字:
if(str > 0)
{
document.getElementById('change').style.color = "Green";
document.getElementById('change').innerHTML = html[1];
}
else
{
document.getElementById('change').style.color = "Red";
document.getElementById('change').innerHTML = html[1];
}
str = html[2];
str = str.replace("+","");
str = str.replace("-","");
if(str > 0)
{
document.getElementById('changePercent').style.color = "Green";
document.getElementById('changePercent').innerHTML = html[2];
}
else
{
document.getElementById('changePercent').style.color = "Red";
document.getElementById('changePercent').innerHTML = html[2];
}
但是对于值-17.91,-5.61,我得到绿色的两个值。错误在哪里?
答案 0 :(得分:1)
var value = $('p').text();
if (value > 0){
$('p').css('color','green');
}
else {
$('p').css('color','red');
}
简单的jQuery
答案 1 :(得分:0)
对于你的变量类型,这可能是奇怪的。我只是怀疑,因为你的变量叫做str。