【发布时间】:2012-01-21 10:50:15
【问题描述】:
我有一个行表,单击时会“扩展”(通过在单击的行之后插入新行),我正在使用 css 对行中的单元格进行斑马样式以及“突出显示”悬停在一行上时单元格的样式。
我希望插入的行与被点击的行具有相同的背景色。
我正在尝试使用 jQuery 使用单击行中第一个单元格的 backgroundColor 属性设置插入行的单元格的背景颜色。
但是,当我这样做时,我得到了“突出显示”颜色,因为我将鼠标悬停在单击的行上 - 我想要非悬停值。
css:
.zebra-striped tbody tr:nth-child(odd) td {
background-color: #f9f9f9;
}
.zebra-striped tbody tr:hover td {
background-color: #f5f5f5;
}
jQuery:
table.find('tbody').find('tr').on('click',function() {
var colourOfRow = $(this).find("td").filter(":first").css('backgroundColor');
var newRows = $('<tr><td style="background-color:'+colourOfRow+';" colspan="'+numCols+'" rowspan="2">Fetching comment...</td></tr><tr></tr>');
newRows.insertAfter($(this));
});
我确信我可以通过在需要使用之前存储颜色来解决这个问题,但我的问题是:
是否有我错过的 jQuery 选择器或其他众所周知的技巧?
【问题讨论】: