基于价值的着色

时间:2013-05-23 09:25:27

标签: javascript jquery html css background-color

我需要根据表格分区中的值为表格着色。 考虑下表

<table bgcolor="#FF0000">
  <tr>
  <td>90%</td>
  </tr>
  <tr>
  <td>80%</td>
  </tr>
  <tr>
  <td>50%</td>
  </tr>
</table>

现在我希望第一行为90%彩色,第二行为80%,第三行为50%。 如何实现这一目标。 感谢

3 个答案:

答案 0 :(得分:2)

$("tr").each(function() {
    var opac = $(this).children().text();
    $(this).css("background-color", "rgba(255, 255,10," + opac + ")");
});

http://jsfiddle.net/wQccw/

答案 1 :(得分:1)

您必须使用$('tr').children().html();

之类的td单元格的值

它将返回可用于设置不透明度的字符串  $('tr').children().css('opacity', newvalue)

您决定如何使用它。返回的字符串将像“80%”,你可以剥离第一个字符并将其解析为整数或只使用SWICH CASE(在80%设置不透明度:0.8等等......)

答案 2 :(得分:1)

$('table').find('td').each(function(){
   $(this).parent().css( {"width":$(this).html(),"float":"left","background-color":'#000'});
});
相关问题