我使用以下 jquery 函数突出显示 Html 表中的行(使用背景颜色)。它工作正常。我的问题是如何从表中选择第二行。“突出显示”是一个类
.highlight td {
background: #E7EFFA;
}
$('#Tabnameabcd tr').mouseover(function() {
if ($.trim($(this).text()) != '')
$(this).addClass('highlight');
}).mouseout(function() {
$(this).removeClass('highlight');
});
which means:
name age depart
test 12 test
test1 13 tested
此处姓名、年龄、出发作为第一行。即标题。 接下来的 test,test1 是 tabe 的元素。如果我使用该 jquery 函数,则应用标题( name,age,depart )。我需要将该 jquery 函数仅应用于以下元素表格不是标题?如何做到这一点?
最佳答案
要获取第二行:$('#Tabnameabcd tr').eq(1)
或 $('#Tabnameabcd tr:eq(1)')
。
要获取第二行中的所有行(演示: http://jsfiddle.net/pXj5F/ ):
$('#Tabnameabcd :nth-child(n+2)')
您还应该考虑 thead
和 tbody
...
关于javascript - 使用 jquery 从 html 表中选择第二行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12488645/