【发布时间】:2014-10-20 06:14:35
【问题描述】:
尝试点击任何表格行,它只会黑色突出显示偶数行,我错过了什么?
它应该在点击时将行背景变为黑色。
这是我当前的代码:
HTML:
<div class="table-responsive">
<table id="tEmprego" class="table table-striped table-hover">
<thead>
<tr>
<th>#</th>
<th>Table heading</th>
<th>Table heading</th>
<th>Table heading</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Table cell</td>
<td>Table cell</td>
<td>Table cell</td>
</tr>
<tr>
<td>2</td>
<td>Table cell</td>
<td>Table cell</td>
<td>Table cell</td>
</tr>
<tr>
<td>3</td>
<td>Table cell</td>
<td>Table cell</td>
<td>Table cell</td>
</tr>
<tr>
<td>4</td>
<td>Table cell</td>
<td>Table cell</td>
<td>Table cell</td>
</tr>
</tbody>
</table>
</div>
CSS:
.table-hover>tbody>tr:hover>td, .table-hover>tbody>tr:hover>th {
background-color: #550055;
color:#eeeeee;
}
.hovered{
background-color: #000000;
color:#ffffff;
}
Javascript:
$("#tEmprego").on('click','td',function() {
$(this).closest("tr").siblings().removeClass("hovered");
$(this).parents("tr").addClass("hovered");
});
【问题讨论】:
标签: css twitter-bootstrap