Javascript 区分大小写过滤器不起作用

标签 javascript

我正在使用下面的脚本,搜索区分大小写不起作用。

(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/

相关文章:

javascript - AngularJS - 在 Jasmine 测试用例中模拟 ngTableParams

javascript - Mocha : Approach to Testing instance of express. 路由器

javascript - 当用户单击重置按钮 JavaScript 时恢复文本字段的默认值

javascript - jquery on click 函数不适用于 bootstrap

javascript - Google App 脚本 - 日期作为字符串操作

javascript - OpenLayers:IE:SCRIPT5:访问被拒绝

javascript - ASP.NET 中从 JSON 返回的未定义数据

javascript - 根据选中的复选框数量生成动态 li 元素

javascript - 为变量分配新值会清除内存中的旧值吗?

javascript - 想要在加载函数之外使用 Clippy.JS 的代理对象