我需要使用帶有jQuery的下拉框過濾表中的行。我想不出如何做的是如何將選項的值與表格行的數據類型聯繫起來。使用數據類型的下拉框jQuery篩選器
HTML:
<label for="filter">Type:</label>
<select id="filter>
<option value="all">All Steps</option>
<option value="standard">Standards</option>
<option value="review">Reviews</option>
</select>
<table id="table>
<tr id="one" class="row" data-type="standard">
<td>Standard</td>
</tr>
<tr id="one" class="row" data-type="review">
<td>Reviews</td>
</tr>
</table>
JS:
$("#filter").change(function() {
$("#table").find(data-type).each(function() {
if ($(this).text() != $("#filter").val())
$(this).hide();
else
$(this).parent().show();
if ($("#filter").val() == "all")
$(this).show();
});
});
jQuery的這裏只是拼湊起來的基於斷我到目前爲止已經通過研究發現身邊。將數據類型屬性留在表格行中非常重要。
我是jQuery的新手,所以任何幫助!
下面的代碼筆:http://codepen.io/aburnsworth/pen/XKzgqa?editors=1111
這個工程除了一兩件事。如果我有另一行具有相同的數據類型,它只顯示該類型的最後一個。我正在使用這個功能將在整個表格中有多個相同的數據類型。 – Andrea
我編輯了我的答案,請大家看看。 – aahhaa
如何在不改變HTML的情況下做到這一點?我無法讓你最後的編輯工作。 – Andrea