【问题标题】:How to search irespective of Case sentive [duplicate]如何搜索不区分大小写[重复]
【发布时间】:2017-03-06 02:46:45
【问题描述】:

在按键时,我正在搜索表格以显示值,但是如何使这项工作不区分大小写

$(document).ready(function()
{
        $('#filter').on('input', function()
        {
                var val = $.trim(this.value).toLowerCase();
                var tr = $('#tagstable tbody td');
                el = tr.find('label:contains(' + val+ ')').closest('td')
                tr.not(el).fadeOut();
                el.fadeIn();
        })
});

http://jsfiddle.net/cod7ceho/216/

【问题讨论】:

标签: jquery


【解决方案1】:

有几种方法可以做到这一点。最接近您已有的可能是使用 filter() 回调,将 needle 和 haystack 协调为小写以进行搜索:

var el = tr.find('label').filter(function(label) {
    return $(this).text().toLowerCase().indexOf(val.toLowerCase()) !== -1;
}).closest('td');

还要注意全局变量 - 您在定义 el 之前缺少 var

【讨论】:

    猜你喜欢
    • 2021-02-18
    • 2017-07-31
    • 1970-01-01
    • 2013-04-01
    • 2013-10-18
    • 1970-01-01
    • 2018-11-21
    • 1970-01-01
    • 2010-09-15
    相关资源
    最近更新 更多