从上一个TR删除样式

时间:2011-07-04 10:21:37

标签: javascript jquery css

我有table我已将tr样式设置为:

border-bottom:1px silver solid;

table是数据库生成的,我不希望最后一个tr具有底部边框。

如何阻止上一个tr获取样式?

5 个答案:

答案 0 :(得分:6)

您可以使用javascript或CSS选择最后一个tr,但如果您选择使用CSS,则无法在所有浏览器上使用(在没有启用JS的浏览器上也不会使用JS解决方案) )。

jQuery的:

$('#tableID tr:last').css('border-bottom',0);

或多个实例:

$('.tableClass tr:last-child').css('border-bottom',0);

CSS解决方案就是使用:

tr:last-child{
border-bottom:0;
}

请注意,:last选择器只选择一个实例,因为它不是CSS规范的一部分,所以它不如last-child选择器快,但选择可能不是如果你有嵌套表等,你在寻找什么。

答案 1 :(得分:2)

使用css2:

table tr:last-child {border: 0;}

答案 2 :(得分:2)

$('table tr:last').css('border-bottom', 'none');

这是一个你可以看到它在行动的小提琴: http://jsfiddle.net/AYzaN/

答案 3 :(得分:1)

使用CSS选择器:

table#mytable tr:last-of-type{
  border-bottom:none;
}

答案 4 :(得分:1)

在CSS3中你可以使用not()选择器,但更好的跨浏览器解决方案(目前)可能是jQuery:

$('table tr:not(:last-child)').css("border-bottom", "1px silver solid");

<强> Demo

相关问题