簡體   English   中英

替換行顏色,除了'no-alternate-color'類

[英]Alternate row color except 'no-alternate-color' class

我在JavaScript文件中有這個表達式...

$('tbody tr:even').addClass("alt-row"); 

它交替顯示我所有表行的顏色,這沒關系。 但我想在tr中添加一個異常類,例如“no-alternate-color”。

<table id="invoice">
  <tbody>
  <tr class="headings">
    <th class="item first" style="padding-left:5px;">Unidad</th>
    <th class="description">Descripcion</th>
    <th class="price">Precio</th>
    <th class="quantity">Cantidad</th>
    <th class="linetotal last" style="padding-right:7px;">Total</th>
  </tr>
  <tr class="lineitem alt-row" style="border-bottom:1px solid #e5e5e5;">
    <td class="item_name_data" style="padding:2px 2px 2px 5px;">MacBook Pro 13"</td>
    <td class="description">13-inch: 2.4 GHz
2.4GHz dual-core
Intel Core i5
    </td>
    <td class="price_data">1199.99</td>
    <td class="quantity_data">2</td>
    <td class="linetotal_data" style="padding-right:5px;">2399.98</td>
  </tr>
  <tr class="lineitem" style="border-bottom:1px solid #e5e5e5;">
    <td class="item_name_data" style="padding:2px 2px 2px 5px;">Muji Table</td>
    <td class="description">awesome light brown table</td>
    <td class="price_data">89.99</td>
    <td class="quantity_data">1</td>
    <td class="linetotal_data" style="padding-right:5px;">89.99</td>
  </tr>
</tbody>
</table>

例如,上面的表最初沒有tr中的“alt-row”類,但它是由jQuery函數添加的。

我對jQuery不太熟悉。 我怎么能做到這一點?

$('tbody tr:not(.no-alternate-color):even').addClass("alt-row");

http://jsfiddle.net/CKeew/

如果你願意的話,你可以單獨使用CSS(取決於你想要完成的任務)......這樣做的東西......

http://jsfiddle.net/xENWM/1/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM