標題可能有點混淆,但這是我能想到的最好的。jQuery:select tr具有所有td動態匹配篩選條件
我需要找到其中包含td
元素匹配提供過濾條件的所有tr
元素。
這是我的樣品,
<tr class="row" id="1">
<td class="philips">PHILIPS</td>
<td class="h4">H4</td>
<td class="lamp">Lamp<td>
</tr>
<tr class="row" id="2">
<td class="philips">PHILIPS</td>
<td class="h5">H5</td>
<td class="bulb">Bulb<td>
</tr>
<tr class="row" id="3">
<td class="neglin">NEGLIN</td>
<td class="w5w">W5W</td>
<td class="tube">Tube<td>
</tr>
<tr class="row" id="4">
<td class="philips">PHILIPS</td>
<td class="h4">H4</td>
<td class="bulb">Bulb<td>
</tr>
<tr class="row" id="5">
<td class="osram">OSRAM</td>
<td class="hb3">HB3</td>
<td class="tube">Tube<td>
</tr>
<tr class="row" id="6">
<td class="neglin">NEGLIN</td>
<td class="w5w">W5W</td>
<td class="lamp">Lamp<td>
</tr>
如果我通過filter[0]
爲 '十字',具有ID的結果返回tr
- 2和
那麼如果我通過第二個過濾器; filter[1]
爲 'H4',結果應被過濾至
- 1和
我試圖this question。
其中有this answer。
$('tr')
.has('td:nth-child(1):contains("Audi")')
.has('td:nth-child(2):contains("red")')
.doSomeThing();
但是,我希望我的過濾器能夠動態應用。我將如何插入第三個has
函數?
我不想去if-else
或switch-case
的方式,如果這是可能的出來他們。
如果您在鏈中取出或添加.nthFilter調用,您可以輕鬆地進行測試,實際上它非常有趣:) – Filip