jQuery如何使用td背景色

时间:2014-03-16 15:37:40

标签: javascript php jquery

$("td").each(function () {
   if($(this).css("background-Color")=="red") {
      $(this).text()=="dd";
   }
   else if($(this).css("background-Color")=="blue") {
      $(this).text("aa");
   }
});

如何以正确的方式编写代码?

1 个答案:

答案 0 :(得分:3)

您可以像这样比较红色:

 if($(this).css("background-Color")=="rgb(255, 0, 0)"){
     ....
 }

和蓝色:

 if($(this).css("background-Color")=="rgb(0, 0, 255)"){
     ....
 }