javascript - 使用 jquery 从 html 表中选择第二行

标签 javascript jquery html dom jquery-selectors

我使用以下 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)')

您还应该考虑 theadtbody...

关于javascript - 使用 jquery 从 html 表中选择第二行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12488645/

相关文章:

javascript - 有没有办法在某些条件下禁用媒体查询?

javascript - Google 跟踪代码管理器延迟 window.load?

html - 什么浏览器下载隐藏图像

javascript - 从函数返回数组并将其分配给变量

java - 在 jsf 2.0 session 超时前 30 秒显示超时窗口

javascript - 为什么 deferred.when() 在完成回调中返回 promise ?

javascript - 如何在网页上的光标上创建镜像效果?

javascript - 比较两个 JSON 并创建具有共同值的 json

使用 D3.js 时 DataTables 中的 Javascript 错误

javascript - 显示可用图像