【发布时间】:2012-05-16 15:32:38
【问题描述】:
当tr 包含包含某些值的td 时,我需要向它添加一个类。
使用this question on SO 的答案,我以为我找到了解决方案,但它似乎不适用于包含多列的行 - 只有在有一个 td 时才有效。
如何识别包含具有特定值的列以及其他列的表行?请注意,列并不总是按特定顺序排列,因此它必须是动态答案。
<table>
<tr>
<td>Hey!</td>
<td>Other column</td>
<td>Yo!</td>
<td>Other column2</td>
</tr>
</table>
<script type="text/javascript">
$('tr').each(function(){
if (($(this).find('td').text() == 'Hey!' ) && ($(this).find('td').text() == 'Yo!' ))
{
alert('here');
$(this).addClass('disabled');
}
});
</script>
【问题讨论】:
标签: jquery jquery-selectors matching