我正在使用下面的脚本,搜索区分大小写不起作用。
(function($){
$.fn.tableSearch = function(options){
if(!$(this).is('table')){
return;
}
var tableObj = $(this),
divObj = $('<label>Search: </label>'),
inputObj = $('<input class="form-control" type="text" />');
inputObj.off('keyup').on('keyup', function(){ var searchFieldVal = $(this).val();
tableObj.find('tbody tr').hide().each(function(){ var currentRow = $(this);
currentRow.find('td').each(function(){
if($(this).html().indexOf(searchFieldVal)>-1){
currentRow.show();
return true;
}
});
});
});
tableObj.before(divObj.append(inputObj));
}
}(jQuery));
我该如何使其不区分大小写?
最佳答案
将搜索词和文本值设为小写:
if ($(this).html().toLowerCase().indexOf(searchFieldVal.toLowerCase()) > -1) { ... }
关于Javascript 区分大小写过滤器不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37608693/