Javascript 如何创建不区分大小写的文本搜索
我有一个搜索功能,它非常适合我的应用程序,只是我不知道如何使它不区分大小写。以下是一些HTML的示例:Javascript 如何创建不区分大小写的文本搜索,javascript,jquery,search,Javascript,Jquery,Search,我有一个搜索功能,它非常适合我的应用程序,只是我不知道如何使它不区分大小写。以下是一些HTML的示例: <div id='search_count'> <div id='count'><?php get_count('notes', 'tasks') ?> </div> <input type="text" id='search_notes' placeholder='Search'/> </div&
<div id='search_count'>
<div id='count'><?php get_count('notes', 'tasks') ?>
</div>
<input type="text" id='search_notes' placeholder='Search'/>
</div>
<div class='task'>
301 closet
</div>
<div class='notes'>
<p>The old manager opened a panel that needs to be closed.</p>
</div>
<div class='task'>vacuum halls </div>
<div class='notes'><p>The halls need to be vacuumed every week!</p></div>
您必须使用以下方法测试两个小写值:
您必须使用以下方法测试两个小写值:
你为什么试图通过HTML解析和搜索。。。我希望这不是用于现实世界。请将搜索的文本和筛选的文本转换为相同的大小写。(这可以在附加变量上完成,以保留已显示的HTML)。我喜欢.toLowerCase(),但是选择你的coice毒药(上v下)为什么你要尝试解析和搜索HTML。。。我希望这不是用于现实世界。请将搜索的文本和筛选的文本转换为相同的大小写。(这可以在附加变量上完成,以保留已显示的HTML)。我喜欢.toLowerCase(),但选择你的coice毒药(上v下)我尝试了这个,在控制台类型中出现了这个错误错误:$(…).filter(…).forEach不是函数我尝试了这个,在控制台类型中出现了这个错误错误错误:$(…).filter(…).forEach不是函数
$("#search_notes").keyup(function () {
var search_notes = $(this).val();
$('.task, .notes').css('display', 'none');
$("div.notes:contains(" + search_notes + ")")
.css('display', 'block')
.prev().css('display', 'block');
var count = $('div.notes').filter(function () {
return $(this).css('display') !== 'none';
}).length;
$('#count').text(count);
});
var search_notes = $(this).val().toLowerCase();
$('.task, .notes').css('display', 'none');
$('div.notes').filter(function() {
return $(this).text().toLowerCase() === search_notes;
}).forEach(function() {
$(this)
.css('display', 'block')
.prev()
.css('display', 'block');
});
var count = $('div.notes').filter(function() {
return $(this).css('display') !== 'none';
}).length;
$('#count').text(count);