2012-07-17 64 views
-1

我檢查一類的表TR元素,比如存在: <tr class="row1 head4"></tr>jQuery的hasClass實施

由語句:
if (that.next().hasClass('.head'+nextRow)){} else if (that.next().hasClass('.head'+(nextRow+1))){}

nextRow具有值範圍從1到5,但它不是加工。語法錯誤?

+1

'.head'應該是'head' – 2012-07-17 09:59:18

回答

1

你不需要一個完整的預先考慮的類名。只有使用「正常」jquery選擇器時才需要完整停止。

0

我不知道,如果是你想要的,但你可以在TR迭代:

<table> 
    <tr class="row1"><td></td></tr> 
    <tr class="row2 head1"><td></td></tr> 
    <tr class="row3"><td></td></tr> 
    <tr class="row4 head3"><td></td></tr> 
</table> 



$('table tr').each(function(i){ 
    if($(this).hasClass('head'+i)) alert($(this).attr('class')); 
}); 

Example