UPPERCASE
如果用小写字母搜索,则此代码未找到,uppercase
反之亦然lowercase
,如果搜索LOWERCASE
. 我正在考虑在搜索之前使用 jquery 将输入和数据标签设为小写,但是如何?
有人可以帮忙吗,谢谢
Here's an updated fiddle for you http://jsfiddle.net/jdmTZ/5/
Remove the data attribute and add it in code:
$('.filter li').each(function() {
$(this).attr('data-label', $(this).text().toLowerCase());
});
Then search by lowercased input
var input = $(this).val().toLowerCase();
Replace line 14 by this:
var matched = $("ul li").filter(function() { return $(this).data('label').toLowerCase().indexOf(input.toLowerCase()) >= 0; });
And change the show()
/hide()
logic:
$('ul li').hide();
matched.show();
matched = matched.length;
This also eliminates the problem of someone entering ]
or some other special character - that would break the CSS rule in your code.
Use toLowerCase()
and $.each
Updated js fiddle code