2

UPPERCASE如果用小写字母搜索,则此代码未找到,uppercase反之亦然lowercase,如果搜索LOWERCASE. 我正在考虑在搜索之前使用 jquery 将输入和数据标签设为小写,但是如何?

jsfiddle代码在这里

有人可以帮忙吗,谢谢

4

3 回答 3

4

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();
于 2013-06-29T19:37:18.633 回答
2

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;

Complete fiddle

This also eliminates the problem of someone entering ] or some other special character - that would break the CSS rule in your code.

于 2013-06-29T19:35:36.340 回答
1

Use toLowerCase() and $.each Updated js fiddle code

于 2013-06-29T19:38:39.760 回答