2012-05-17 32 views
1

我有一個表像數:如何找到細胞的表不包含某個類的圖像

<table> 
    ... 
    <td class="projectapproval"> 
    <img src="../../Content/Images/stock_lock.gif" alt="locked" class="lockicon invisibleforprint" /> 
    </td> 
    <td class="projectapproval"> 
    </td> 
    <td class="projectapproval"> 
    </td> 
    ... 
</table> 

我所擁有的是:

$('table td.projectapproval img.lockicon').length 

哪將用鎖圖標計算表格中的單元格數量。

我想要的是統計沒有鎖圖標的表格中的單元格數量。兩個在這種情況下。

有沒有人知道一個很好的方法來做到這一點?

我當然可以去:

$('table td.projectapproval).length - $('table td.projectapproval img.lockicon').length 

但我真的想一個更清潔的方式。有一個存在嗎?

回答

2

試試這個

$('table td.projectapproval:not(:has(img.lockicon))') 
0

的另一種方法是使用過濾功能:

$('table td.projectapproval').filter(function() { 
    return !$(this).children('img.lockicon').length; 
    // use the find function if you're not looking for immediate children: 
    return !$(this).find('img.lockicon').length; 
})