我有一个功能,用于使用一个文本框在我的网络中搜索内容,<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();
}
});
Run Code Online (Sandbox Code Playgroud)
这工作正常,但仅适用于完全匹配,如果我在文本框中写入Hello只显示Hello单词但我需要显示hello,hEllO或HELLO, 所有字符串,无论大小写。
非常感谢任何帮助,抱歉我的语法不好。
将搜索字符串和您要搜索的文本都转换为小写:
return $(this).text().toLowerCase().indexOf(term.toLowerCase()) > -1
Run Code Online (Sandbox Code Playgroud)
尝试使用toLowerCase()函数来绕过区分大小写的匹配,例如:
$(this).text().toLowerCase().indexOf(term.toLowerCase()) > -1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9215 次 |
| 最近记录: |