【发布时间】:2018-05-14 10:44:25
【问题描述】:
我有一个带有线条的数据表,当我单击一行时,我想更改背景颜色:选择行中的红色,而其他行我想留下背景颜色:白色
我试试这个:
$(document).on('click', "#table_user tr:not(:first) td:first-child", function() {
var row_num = parseInt( $(this).parent().index() )+1;
if(row_num == $(this).closest('tr').index()+1){
$(this).css({'background-color':'red'});
}else{
$(this).css({'background-color':'white'});
}
});
但它不起作用
【问题讨论】:
-
if 条件永远为真。
-
所有线条一开始都是白色的?