CSS / JQuery - 过滤表行并反转选择
我有一个包含多行的表,然后我想突出显示包含值 x 的行,然后反转选择。
到目前为止,我能够选择包含过滤器值的行,但反转它会给我带来问题。
首先,我选择与我的搜索值匹配的行并添加类名:
var rows = $("#table tbody tr td:nth-child(1):contains('" + searchValue + "')");
$(rows).parent().addClass('filtered');
然后我尝试添加一个没有“过滤”类名的类名,这是我无法正确执行的行
$('#table tbody tr:not(.filtered)').addClass('hidden');
:隐藏类最终出现在所有行上。
有人有什么想法吗?
谢谢,
马丁
I have a table with a number of rows, I then want to highlight the rows that contain value x and then invert the selection.
So far I am able to select the rows that contains the filter value but inverting it is giving me problems.
First I am selecting the rows that match my search value and add a class name:
var rows = $("#table tbody tr td:nth-child(1):contains('" + searchValue + "')");
$(rows).parent().addClass('filtered');
Then I am trying to add a class name that doesn't have the 'filtered' class name, this is the line that I just cant get right:
$('#table tbody tr:not(.filtered)').addClass('hidden');
The class hidden ends up on all rows.
Anyone got any ideas?
Thanks,
Martin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我尝试过: http://jsfiddle.net/eYRWj/ 但没有。它按预期工作。
尝试
console.log(rows)
(安装了 firebug 并启用了控制台),看看它们是否真的被标记为.filtered
,即搜索是否成功。I tried it: http://jsfiddle.net/eYRWj/ it doesn't. It works as expected.
Try
console.log(rows)
(with firebug installed and its console enabled), to see if they are really marked as.filtered
, i.e. if the search succeeded.尝试使用双引号,如下所示:
$('#table tbody tr:not(".filtered")').addClass('hidden');
try with double quotes like this:
$('#table tbody tr:not(".filtered")').addClass('hidden');