[英]Search text no matter if is in lower or upper case
我有一個 function 用於使用一個文本框搜索 web 中的內容<input class="form-control" id="search" type="text" placeholder="Search" />
顯示的內容在不同的面板中,所以這是我的script
。
$('#search').keyup(function () {
var term = $(this).val();
if (term != '') {
$('.panel').hide();
$('.panel').filter(function () {
return $(this).text().indexOf(term) > -1
}).show();
} else {
$('.panel').show();
}
});
這很好,但只有完全匹配,如果我在文本框中寫Hello
只顯示Hello
單詞,但我需要顯示hello
, hEllO
或HELLO
,所有字符串,無論大小寫。
非常感謝任何幫助,對我的語法錯誤感到抱歉。
將搜索字符串和要搜索的文本都轉換為小寫:
return $(this).text().toLowerCase().indexOf(term.toLowerCase()) > -1
嘗試使用toLowerCase()
函數通過區分大小寫的匹配,例如:
$(this).text().toLowerCase().indexOf(term.toLowerCase()) > -1
我知道我遲到了六年,但他的回答很有幫助,因為有更少的東西可以混淆。 我不會阻止任何人指導別人。
同時使用.toUpperCase()
輸入值和過濾器值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.