【发布时间】:2017-07-27 16:33:30
【问题描述】:
我正在尝试使用和多个 select2 框的类过滤表。
表格 HTML
<table class="table">
<tbody>
<tr class="kanban-event Austin">
<td>...</td>
</tr>
<tr class="csm-event Charlotte">
<td>...</td>
</tr>
<tr class="cal-event Charlotte">
<td>...</td>
</tr>
<tr class="cspo-event Austin">
<td>...</td>
</tr>
<tr class="cal-event Raleigh">
<td>...</td>
</tr>
<tr class="kanban Charlotte">
<td>...</td>
</tr>
<tr class="cspo-event Austin">
<td>...</td>
</tr>
<tr class="csm-event Charlotte">
<td>...</td>
</tr>
<tr class="safe-event Austin">
<td>...</td>
</tr>
<tr class="cspo-event Raleigh">
<td>...</td>
</tr>
<tr class="csm-event Charlotte">
<td>...</td>
</tr>
<tr class="csm-event Raleigh">
<td>...</td>
</tr>
</tbody>
</table>
选择 HTML
<select id="location">
<option value="all">All Locations ...</option>
<option value="Austin">Austin, TX</option>
<option value="Charlotte">Charlotte, NC</option>
<option value="Raleigh">Raleigh, NC</option>
</select>
<select id="course">
<option value="all">All Courses ...</option>
<option value="csm">Certified Scrum Master (CSM)</option>
<option value="cspo">Certified Scrum Product Owner (CSPO)</option>
<option value="cal">Certified Agile Leadership (CAL)</option>
<option value="safe">Scaled Agile Framework (SAFe®)</option>
<option value="kanban">Kanban</option>
</select>
当前的 JS
jQuery(function() {
jQuery("#course").on("select2-selecting", function (evt) {
// console.log(evt.val);
// console.log(jQuery('#events-table tr:not(".'+evt.val+'-event")'));
jQuery('#events-table tr').show();
jQuery('#events-table thead tr').show();
jQuery('#events-table tr:not(".'+evt.val+'-event")').hide();
jQuery('#events-table thead tr').show();
if (evt.val == '') {
jQuery('#events-table tr').show();
jQuery('#events-table thead tr').show();
}
});
jQuery("#location").on("select2-selecting", function (evt) {
// console.log(evt.val);
// console.log(jQuery('#events-table tr:not(".'+evt.val+'")'));
jQuery('#events-table tr').show();
jQuery('#events-table thead tr').show();
jQuery('#events-table tr:not(".'+evt.val+'")').hide();
jQuery('#events-table thead tr').show();
if (evt.val == '') {
jQuery('#events-table tr').show();
jQuery('#events-table thead tr').show();
}
});
});
当前的 JS 允许过滤到表,但一次只处理一个过滤器。我想知道如何使选择一起工作,例如让 CSM Events in Austin 显示而隐藏其他所有内容?
提前致谢。
编辑:这是一个小提琴https://jsfiddle.net/5202jsax/6/
【问题讨论】:
-
加个jsfiddle就好了。
-
@PandhiBhaumik - 添加了小提琴
标签: javascript jquery html jquery-select2