2012-07-27 41 views
2

的代码都与IE浏览器这样的工作持续TR表:最后是不是一种选择如何添加类使用jQuery

<table class="ms-main" cellpadding="0" cellspacing="0" border="0" width="100%" height="100%"> 
<tr>..</tr> 
<tr>..</tr> 
<tr>..</tr> 
<tr class=add this value including class=>..</tr> 
</table> 

预先感谢您

EDIT1:

如果源文件是这样的呢?

<table class="ms-main" cellpadding="0" cellspacing="0" border="0" width="100%" height="100%"> 
<tr>..</tr> 
<tr>..</tr> 
<tr>..</tr> 
<tr class=add this value including class=>**<table>more nested tables here</table>**</tr> 
</table> 

回答

1

:last在IE中可以正常工作。

jQuery手动实现它,它与浏览器支持的CSS选择器没有关系。

$('.ms-main tr:last').addClass('name-of-class'); 

Here's a nice article对jQuery的实施滋滋选择和使用querySelectorAll

至于你的编辑,你可能需要使用>表示,该tr应立即孩子,而不是更遥远后裔。不过,请注意tbody

0

$('table tr').last().addClass('myClass');

:last-child选择未在IE 6-8,使用方法支持最后()来找到最后一个元素在DOM

0
<script> 
    $("table tr:last").addClass("lastOne"); 
</script>