我對JQuery來說比較新。我在下面的小提琴中借用了代碼(對不起,不引用作者,但我忘記了代碼的來源)並稍微修改它以實現我的總體目標。Jquery隱藏一個表的行但不是另一個
我基本上有兩張表,一張帶有id和class,另一張沒有。我不能輕易地給non-id/class表一個id/class,因爲我在另一個應用程序中使用了JQuery,並沒有那麼多的控制權。
我想要的是搜索功能只搜索和過濾非id/class表(下面的第一個表/小提琴)。因此,在這個小提琴的情況下,我希望搜索功能搜索/過濾不是id =「myTable」class =「test1」(第一個表格)的表格。現在它過濾兩者。
我不知道這個代碼是否是最好的,所以我願意提供建議。謝謝!
<label for="kwd_search">Search:</label> <input type="text" id="kwd_search" value=""/>
<table border="1" style="border-collapse:collapse">
<thead>
<tr>
<th>Name</th>
<th>Sports</th>
<th>Country</th>
</tr>
</thead>
<tbody>
<tr>
<td>Sachin Tendulkar</td>
<td>Cricket</td>
<td>India</td>
</tr>
<tr>
<td>Tiger Woods</td>
<td>Golf</td>
<td>USA</td>
</tr>
<tr>
<td>Maria Sharapova</td>
<td>Tennis</td>
<td>Russia</td>
</tr>
</tbody>
</table>
<br>
<table id="myTable" class="test1" border="1" style="border-collapse:collapse">
<thead>
<tr>
<th>Name2</th>
<th>Sports2</th>
<th>Country2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Sachin Tendulkar2</td>
<td>Cricket2</td>
<td>India2</td>
</tr>
<tr>
<td>Tiger Woods2</td>
<td>Golf2</td>
<td>USA2</td>
</tr>
<tr>
<td>Maria Sharapova2</td>
<td>Tennis2</td>
<td>Russia2</td>
</tr>
</tbody>
</table>
小提琴:http://jsfiddle.net/aPLLF/66/
謝謝!這是一個很好的答案!它絕對回答了我問的問題。然而,我的小提琴是我試圖實現的一個非常簡化的版本。如果有兩個以上的桌子呢?我的實際應用程序比現在更注重計數,全部使用不同的編號和類別。 :) 類似於:http://jsfiddle.net/aPLLF/72/ – gothmog721
只要你喜歡,你可以使用盡可能多的':not()'標識符...... http://jsfiddle.net/qzqyf/ – Archer