我有一个生成的表AngularJS.
这是我的 HTML:
<table class="my_table">
<thead>
<tr>
<th>Name</th>
<th>Address</th>
<th>Celphone</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="contact in contacts">
<td>{{contact.Name}}</td>
<td>{{contact.Address}}</td>
<td>{{contact.Celphone}}</td>
</tr>
</tbody>
</table>
我希望每一行在“悬停”时改变颜色,在“单击”时改变颜色,所以我用 CSS 尝试了这一点:
<style>
.my_table tbody tr:hover {
background-color: #7fccee; /*--- this is a blue color when hover ---*/
}
.my_table tbody tr:focus {
background-color: #f3f3f3; /*--- this is a gray color when clicked---*/
}
</style>
悬停效果完美,但是Focus不管用! (奇怪的是,在浏览器控制台中,如果我选择该行并且“力元素状态:焦点“然后它将焦点应用到该行)
我还尝试将 SCRIPT 与 jquery 一起使用:
$(document).ready(function() {
$('.my_table tbody tr').click(function() {
$(this).addClass('active'); //I'm adding the color gray with css to '.active'
});
});
但这也行不通,我做错了什么?