如何添加类来追加td元素

时间:2017-04-11 09:33:56

标签: 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>
<tbody  class="colorredd"></tbody>
 </table>

这里是我追加项目的方式:

$(obj).each(function () {
var tbl3Row = "<tr " + (parseInt(obj.Total) > 3 ? " class='colorred'" : "") + (parseInt(obj.Total) < 4 ? " class='colorred'" : "") + ">" + "<td>" + obj.Title + "</td>" + "<td>" + obj.Total + "</td>" + "</tr>"
 table3Rows += tbl3Row;
});
 }

它会闪烁桌面上的两行。 我想要做的只是第二行眨眼。 我猜我需要将类添加到Total td之外,只需从html tbody中删除该类。 但我不知道如何才能特别为td添加类。

var tbl3Row = "<tr " + (parseInt(obj.Total) > 3 ? " class='colorred'" : "") + (parseInt(obj.Total) < 4 ? " class='colorred'" : "") + ">" + "<td>" + obj.Title + "</td>" + "**<td>**" + obj.Total + "</td>" + "</tr>"

和她的我的css:

.colorred td:nth-child(2){
    background-color:red;

}

1 个答案:

答案 0 :(得分:0)

它会闪烁两行,因为您将fadeIn / Out绑定到class Record { //Reads a single record from "from", incrementing the associated // read pointer, and returning eof or bad, depending on whether record // state is consistent, and whether eof stream is reached std::istream& read(std::istream& from); //Writes a single record to "to" std::ostream& write(std::ostream& to); } struct MaterialStore { //Reads all records from "from", in sequence, using Record interface std::istream& read(std::istream& from); //Writes all records in "to" to, in sequence, using Record interface std::ostream& write(std::ostream& to); //Perhaps to perform that seeking for a specific record, the // Use Record interface for retrieval. std::iostream& seekRecord(std::iostream& stream, int index pos); const Record& getRecords(); //Returns all the records read } 类。这是每一行。

将另一个类(可能是colorredd)添加到最后一个表行。然后眨眼就可以了。

lastRow