我正在尝试使搜索不敏感,但它只匹配大写字母,我想用大写和小写进行搜索.这是我的代码,
function keyup(idd){
var searchTerm = $("#tags"+idd).val();
$("#sss"+idd+' option').each(function(){
if($(this).text().match(searchTerm)){
$(this).show();
}
else{
$(this).hide();
}
});
}
任何人都可以帮助我。谢谢
而不是匹配,你可以尝试这样的事情
if(string1.toUpperCase() == string2.toUpperCase())
改用构造函数:
$(this).text().match(new RegExp(searchTerm, "i"))
使用 toLowerCase()
.
if ($(this)
.text()
.toLowerCase()
.match(searchTerm.toLowerCase())) {
$(this)
.show();
} else {
$(this)
.hide();
}
使用带有忽略大小写选项的正则表达式匹配器
var regEx = new RegExp('abc', "i");
console.log(regEx.test('Abc'));
console.log(regEx.test('ABC'));
console.log(regEx.test('AAA'));