【问题标题】:select the second row from the html table using jquery使用jquery从html表中选择第二行
【发布时间】:2012-09-19 04:34:36
【问题描述】:

我使用以下 jquery 函数突出显示 Html 表中的行(使用 bg 颜色)。它工作正常。我的问题是如何从表中选择第二行。'highlight' 是一个类

.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 函数,则 title(name,age,depart) 是适用的。我只需要将该 jquery 函数应用于表格不是标题?怎么办?

【问题讨论】:

  • 将标题行放在thead元素中,将id放在tbody元素中。考虑使用event.target 获取行,然后从那里开始的 tbody 上的单个侦听器,而不是每一行上的侦听器。

标签: javascript jquery html dom jquery-selectors


【解决方案1】:

要获得第二行:$('#Tabnameabcd tr').eq(1)$('#Tabnameabcd tr:eq(1)')

从第二个获取所有行(演示:http://jsfiddle.net/pXj5F/):

$('#Tabnameabcd :nth-child(n+2)')

您还应该考虑theadtbody...

【讨论】:

  • 它对我不起作用..如果我这样使用,我没有让课程从第二行申请..
  • name age depart
    然后我输入相同结构中的元素。我没有使用
  • @ Speransky Danil 如果我这样使用 $('#Tabnameabcd :nth-child(n+2)')。整个表格将在 mouseover 上突出显示。由于某些原因我没有使用 th元素,ents
【解决方案2】:

这样试试

$('#mytable_id tr').eq(1).(your function here);

如果你想申请行而不是倾斜,那么你也可以使用

$("#mytable_id td").function({
      //Play here
});

它将适用于除标题之外的所有表的 td。您也可以使用“.not()”函数代替此

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-28
    • 2016-11-09
    • 2012-08-08
    • 2012-03-03
    • 1970-01-01
    • 2010-10-24
    • 1970-01-01
    • 2010-12-21
    相关资源
    最近更新 更多