我想从搜索条件中删除区分大小写的功能。如果我输入小写字母,我希望它同时搜索小写和大写字母。
$('#search').click(function(){
$('.contact-name').hide();
var txt = $('#search-criteria').val();
$('.contact-name:contains("' + txt + '")').show();
});
最佳答案
:contains
选择器默认区分大小写。如果您想使其不区分大小写,则需要使用 filter()
实现自己的逻辑,以使元素的文本和值搜索相同的大小写。像这样的事情:
$('#search').click(function(){
$('.contact-name').hide();
var txt = $('#search-criteria').val();
$('.contact-name').filter(function() {
return $(this).text().toLowerCase().indexOf(txt.toLowerCase()) != -1;
}).show();
});
关于javascript - 从搜索 jquery 中删除区分大小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34021433/