简体   繁体   English

如何从搜索输入 noinpepend 的小写或大写 jQuery 中过滤表值

[英]How to filter table values from search input noinpepend of lower or upper case jQuery

I working with table data filtering, and I have issues.我使用表数据过滤,我遇到了问题。

At this moment I create a script which is filtering data depends on user typing in the search field, but problem is, in case if a user will write the same keywords, for example, "Apple" but with lower case "apple" , the filter will not work.此时我创建了一个脚本,该脚本根据用户在搜索字段中的输入来过滤数据,但问题是,如果用户编写相同的关键字,例如"Apple"但使用小写"apple" ,则过滤器将不起作用。

My code:我的代码:

$(document).ready(function () {
    $('.search').keyup(function () {
        searchTable($(this).val());
    });
});

function searchTable(inputVal) {
    var table = $("#fruit-table");
    table.find('tr').each(function (index, row) {
        var allCells = $(row).find('td');
        if (allCells.length > 0) {
            var found = false;
            allCells.each(function (index, td) {
                var regExp = new RegExp(inputVal, 'i');
                if (regExp.test($(td).text())) {
                    found = true;
                    return false;
                }
            });
            if (found == true) $(row).show();
            else $(row).hide();
        }
    });
}

But I want some flexible approach, which are will filter independently if the user will type from the upper or lower case, and in the end, he will get the same result.但我想要一些灵活的方法,如果用户从大写或小写输入,它们将独立过滤,最后,他会得到相同的结果。

Try this solution.试试这个解决方案。

function searchTable(inputVal) {
  var table = $("#fruit-table");
  table.find('tr').each(function (index, row) {
    var allCells = $(row).find('td');
    if (allCells.length > 0) {
        var found = false;
        allCells.each(function (index, td) {
            inputVal = inputVal.toLowerCase();
            var regExp = new RegExp(inputVal, 'i');
            var tableData = $(td).text().toLowerCase();
            if (regExp.test(tableData)) {
                found = true;
                return false;
            }
        });
        if (found == true) $(row).show();
        else $(row).hide();
    }
 });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 小写和大写的数据属性搜索 - Data attribute search with lower case and upper case 如何使用大写/小写 - How to use Upper/Lower case 如何在触发jquery中的select更改时忽略大小写(大写/小写)? - How to ignore case (upper/lower) while triggering change for select in jquery? 搜索文本,无论是小写还是大写 - Search text no matter if is in lower or upper case 我如何从jquery的筛选器栏中获取较低和较高的值 - how can i get the lower and upper value from the Filter bar in jquery 编写一个程序来读取用户的输入并将小写字母与大写字母区分开,并检查是否两次引入了字符 - Making a program that reads input from user and distincts lower case from upper case, and checks if a character is introduced twice 如何根据大小写的文本匹配过滤动态嵌套的 JSON 对象数组 - How to filter Dynamic nested array of JSON objects based on text match with both upper and lower case 如何让我的反应搜索引擎同时接受大写和小写字母? - How can I make my react search engine to accept both upper and lower case letters? (Javascript)搜索特定项目时如何忽略在搜索栏中注册的小写/大写 - (Javascript) How do you ignore lower/upper case being registered in search bars when searching for a specific item 无法使用搜索检测到大写或小写 - Cannot detect individual UPPER or lower case using search
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM