我在我的 jsfiddle 中做了一个搜索选项:http://jsfiddle.net/alonshmiel/46wyH/33/
所以我有一个值(value
是搜索到的文本)。
我搜索所有包含值的 li:value
// hide all the lists
$('#searchExcludeResult li').each(function() {
$(this)[0].style.display = "none";
});
// show all the li that contains the value: value
$('#searchExcludeResult li:contains(' + value + ')').each(function() {
$(this)[0].style.display = "list-item";
$(this)[0].innerHTML = $(this)[0].textContent.replace(value,
'<span style="font-weight: bold">' + value + '</span>');
});
它可以工作,但无论搜索的文本是小写还是大写,我都希望它能工作。
例如:
<ul>
<li>United States</li>
<li>London, England</li>
<li>Moskow, Russia</li>
</ul>
搜索到的文本是:e
,显示第一个(unit e d stat e s)和第二个li(London, 英国)。
搜索到的文本可以是EN
, eN
, l
, L
等
感谢任何帮助!
最佳答案
使用.filter()并匹配.toLowerCase() .text()
.
$('#searchExcludeResult li').filter(function () {
return $(this).text().toLowerCase().indexOf(value.toLowerCase()) !== -1;
}).each(function () {
关于javascript - 搜索选项不适用于小写和大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21967014/