Javascript 如何将类添加到附加的td元素中

Javascript 如何将类添加到附加的td元素中,javascript,jquery,css,Javascript,Jquery,Css,我试图用jquery在表行上显示闪烁的颜色 (function blink() { $('.colorredd').fadeOut(500).fadeIn(500, blink); })(); 这里是html部分 <table id="userdata3" border="2"> <thead> <th>Afdeling</th> <th>Åben</th> </thead> <tb

我试图用jquery在表行上显示闪烁的颜色

(function blink() {
 $('.colorredd').fadeOut(500).fadeIn(500, blink);
 })();
这里是html部分

  <table id="userdata3" border="2">
 <thead>
   <th>Afdeling</th>
  <th>Åben</th>
 </thead>
<tbody  class="colorredd"></tbody>
 </table>

它会同时闪烁两行,因为您正在将fadeIn/Out绑定到
colorredd
类。每一排都有

将另一个类(可能是
lastRow
)仅添加到最后一个表行。和它绑定

(function blink() {
 $('.lastRow').fadeOut(500).fadeIn(500, blink);
 })();

是的,我知道我需要将其绑定到最后一行。问题是我该怎么做。它是动态行而不是静态行。如果是一次性从
obj
数组创建行,则可以在
每个
中添加一个条件以查找最后一个索引(obj.length-1==索引)。如果要动态添加更多行,则必须删除已经存在的类并将其添加到新添加的行中。
var tbl3Row = "<tr " + (parseInt(obj.Total) > 3 ? " class='colorred'" : "") + (parseInt(obj.Total) < 4 ? " class='colorred'" : "") + ">" + "<td>" + obj.Title + "</td>" + "**<td>**" + obj.Total + "</td>" + "</tr>"
.colorred td:nth-child(2){
    background-color:red;

}
(function blink() {
 $('.lastRow').fadeOut(500).fadeIn(500, blink);
 })();