2012-07-27 35 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>