[英]Case insensitive jQuery search filter
我在Jquery腳本上有一些幫助,它創建了一個可搜索的過濾器,代碼可以在這里看到:
$('#search-keyword').on( "keyup", function(){
if($(this).val()){
var input = $(this).val();
$(".filter").hide();
$("div[data-destination*='"+ input +"']").show();
if(!$('.filter:visible').get(0)){
$(".filter").show();
}
}else{
$(".filter").show();
}
});
麻煩的是,如果有一個大寫字母“H”的單詞“How”並且我搜索“h”,它就找不到它。 如何使此腳本不區分大小寫?
替換這個:
$(".filter").hide();
$("div[data-destination*='"+ input +"']").show();
有了這個:
$(".filter div[data-destination]").hide(); // You have to hide the elements (the divs you want to filter) not the container.
$(".filter div[data-destination]").filter(function() {
return $(this).data("destination").toLowerCase().indexOf(input.toLowerCase()) !== -1;
}.show();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.