<table class="tb_list"></table>
1 $(function(){ 2 $(".tb_list td").each(function(i,n){ 3 var text = $.trim($(n).text()); 4 var fVal = parseFloat(text); 5 if(!isNaN(fVal) && fVal < 0){ 6 $(n).css("color","red"); 7 } 8 }); 9 });
2 当td里面有两个值时(示例中分隔符为<br>),代码如下
1 $(function () { 2 $(".tb_list td").each(function (i, n) { 3 //var txt = $.trim($(n).text()); 4 var txt = $(n).html(); 5 var arr = []; 6 try{ 7 arr = txt.split("<br>"); 8 }catch(e){} 9 var innTxt = ""; 10 if(arr.length == 2){ 11 if (parseFloat(arr[0]) < 0 || parseFloat(arr[1]) < 0) { 12 if (parseFloat(arr[0]) < 0) { 13 innTxt += "<font color=‘red‘>" + arr[0] + "</font>"; 14 } 15 else innTxt += arr[0]; 16 if (parseFloat(arr[1]) < 0) { 17 innTxt += "<br><font color=‘red‘>" + arr[1] + "</font>"; 18 } 19 else innTxt += "<br>" + arr[1]; 20 $(n).html(innTxt); 21 } 22 } 23 }); 24 });
时间: 2024-10-02 05:43:32