【问题标题】:How to set a css class to table header cell如何将css类设置为表格标题单元格
【发布时间】:2015-04-01 10:01:42
【问题描述】:

我有一个带有单元格的表格。 我想仅在此“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/

谢谢。

【问题讨论】:

标签: javascript html css


【解决方案1】:

使用这个

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

【讨论】:

    猜你喜欢
    • 2012-06-14
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 2019-01-01
    • 2013-05-31
    • 2019-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多