参考我之前的帖子:
我的 HTML
<table class="table table-bordered table-condensed table-striped">
<thead>
<tr>
<th>Col 1</th>
<th>Col 2</th>
<th>Col 3</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Data 1</strong></td>
<td>Data 2</td>
<td>Data 3</td>
</tr>
<tr>
<td><strong>Data 1</strong></td>
<td>Data 2</td>
<td>Data 3</td>
</tr>
<tr>
<td><strong>Data 1</strong></td>
<td>Data 2</td>
<td>Data 3</td>
</tr>
</tbody>
</table>
jQuery
$(document).ready(function(){
$('table.table-striped tr').on('click', function () {
$(this).find('td').css('background-color', '#ff0000');
// toggleClass doesn't seem to work
});
});
我正在尝试通过单击事件将行颜色关闭。知道这是否可以使用用户定义的 css 选择器?