【发布时间】: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