我有一個基本的表,並希望通過幾個過濾器過濾錶行。jquery - 過濾表格按行單元格內容第一個字母
<select id="location">
<option value="New York">New York</option>
<option value="LA">LA</option>
<option value="Boston">Boston</option>
</select>
<select id="last-name">
<option>Last name</option>
<option value="ABCDE">A-E</option>
<option value="FGHIJ">F-J</option>
<option value="KLMNO">K-O</option>
<option value="PQRST">P-T</option>
<option value="UVWXYZ">U-Z</option>
</select>
<table id="personnel">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Location</th>
</tr>
</thead>
<tbody>
<tr>
<td class="firstname">Abel</td>
<td class="lastname">Alpha</td>
<td class="location">LA</td>
</tr>
<tr>
<td class="firstname">Benny</td>
<td class="lastname">Bravo</td>
<td class="location">New York</td>
</tr>
<tr>
<td class="firstname">Cindy</td>
<td class="lastname">Charlie</td>
<td class="location">Boston</td>
</tr>
<tbody>
</table>
第一濾波器我想我可以做這樣的事情:
$(function() {
$('#location').change(function() {
$("#personnel td.location:contains('" + $(this).val() + "')").parent().show();
$("#personnel td.location:not(:contains('" + $(this).val() + "'))").parent().hide();
});
});
但隨着第一個字母過濾器,我需要一些幫助。
你不解釋你的代碼有什麼問題。 – Nelson