jquery过滤不区分大小写 [英] jquery filtering case insensitive

查看:339
本文介绍了jquery过滤不区分大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了这个过滤脚本:



jsfiddle。 net / Zhd2X / 574 /



尝试在第一个表格列中按 f F 布尔值。在原始版本中,例子中只有 f ,但是我在行号中添加了 .toLowerCase() 。 17.
但是当您在第二个表格 - 专栏中按 g G 时,我的第一次更新过滤不起作用。我必须改变行号。 18,但我没有任何想法...

解决方案

您需要将过滤之前 小写。目前,您只是将过滤器输入的值设为小写。

  var criteria = this.value.toLowerCase(); 

table.find(el).filter(function(_,td){
return $(td).text()。toLowerCase()。indexOf(criteria)== -1 ;
})。parent()。hide();



这是一个更新的小提琴


I found this filtering script:

jsfiddle.net/Zhd2X/574/

Try to press f and F in first table - column boolean. In original version example was working only with f but I added .toLowerCase() in line no. 17. But when you press g or G in second table - column speciality, filtering not working by my first update. I must to change line no. 18, but i dont have any idea...

解决方案

You need to make the text of the <td>s lowercase before filtering. Currently you're only making the value of the filter input lowercase.

var criteria = this.value.toLowerCase();

table.find(el).filter(function(_, td) {
    return $(td).text().toLowerCase().indexOf(criteria) == -1;
}).parent().hide();

Here's an updated fiddle

这篇关于jquery过滤不区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆