簡體   English   中英

如何將CSS類設置為表標題單元格

[英]How to set a css class to table header cell

我有一張桌子,上面放着細胞。 我只想在“ th”的值為“ ID”的情況下將css類設置為“ th”。

我嘗試了這個:

var T = [];
$('.tbl > thead > tr > th').each(function(){
    T.push($(this).text())
 })
for (var i = 0; i < T.length; i++) {
    if (T[i] == "ID" ) {$('.tbl thead tr th').addClass('Myclass')};
}

但是此代碼將類“ Myclass”設置為表的所有標頭。

<thead> 
    <tr>  
        <th class="Myclass">ID</th> 
        <th class="Myclass">NOm</th>
    </tr>
</thead>

這是一個小提琴-> http://jsfiddle.net/1ck4joum/1/

謝謝。

用這個

$('.tbl thead tr th:contains("ID")').addClass('Myclass')};

暫無
暫無

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

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