【发布时间】:2023-03-17 19:40:01
【问题描述】:
我有一个表,其中包含一个包含关键字的列和一个包含与这些关键字对应的选项和值的选择字段(css 类 .filter)。
在我将选择字段更改为另一个选项之前,它工作正常。使用下面的代码,一切都被明显地隐藏了。但是在隐藏之前为每一行添加一个 .show() 不起作用(不再隐藏任何东西)。隐藏后显示选定的行也不行。
$(".filter").change(function () {
if ($(this).val() != "all") {
$("tbody").find("tr:not(:contains('"+$(this).val()+"'))").hide(); //hide everything except what contains the selected option
} else {
$("tbody").find("tr:hidden").show(); // reset the filter and show everything
}
});
【问题讨论】: