javascript - 如何使我的搜索功能不区分大小写?
问题描述
我正在做一个 Electron 项目,但我在搜索功能方面遇到问题,我找不到解决方案,希望你能帮助我。
我做了一个简单的搜索功能,其中一个表格填充了结果,它适用于name
, lastname
, ID
,等。但是andemail
有一个问题,区分大小写。name
lastname
这是代码:
function buscar()
{
var busqueda = document.getElementById("busqueda").value;
con.query("SELECT * FROM candidata", function (err, result, fields)
{
if (err) console.log(err);
var tam = result.length;
var text;
for (i = 0; i < tam; i++)
{
if((busqueda == result[i].nom_can)
|| (busqueda == result[i].ci_can)
|| (busqueda == result[i].ape_can)
|| (busqueda == result[i].ocu_can)
|| (busqueda == result[i].email_can)
|| (busqueda == result[i].mun_can)
|| ((busqueda == result[i].nom_can+" "+result[i].ape_can)))
{
text += '<tbody>';
text += '<tr>';
text += '<td>';
text += result[i].ci_can;
text += '</td>';
text += '\t\t';
text += '<td>';
text += result[i].nom_can;
text += ' ';
text += result[i].ape_can;
text += '</td>';
text += '\t\t';
text += '<td>';
text += result[i].fky_cat;
text += '</td>';
text += '\t\t';
text += '<td>';
text += result[i].mun_can;
text += '</td>';
text += '\t\t';
text += '<td>';
text += result[i].est_can;
text += '</td>';
text += '\t\t';
text += '<td>';
text += '</td>';
text += '</tr>';
text += '</tbody>';
}
document.getElementById("find").innerHTML= text;
}
});
}
我需要使它不区分大小写,我已经尝试过了,var busqueda = document.getElementById("busqueda").value.toLowerCase();
但没有显示任何内容。
编辑:找到了一个解决方案,也许不是一个花哨的解决方案,但它按我想要的方式工作,谢谢!
function buscar()
{
var busqueda = document.getElementById("busqueda").value;
con.query("SELECT * FROM candidata", function (err, result, fields)
{
if (err) console.log(err);
var tam = result.length;
var text;
for (i = 0; i < tam; i++)
{
if
(
(busqueda == result[i].nom_can.toLowerCase())
|| (busqueda == result[i].nom_can)
|| (busqueda == result[i].ci_can)
|| (busqueda == result[i].ape_can.toLowerCase())
|| (busqueda == result[i].ape_can)
|| (busqueda == result[i].ocu_can.toLowerCase())
|| (busqueda == result[i].ocu_can)
|| (busqueda == result[i].email_can.toLowerCase())
|| (busqueda == result[i].email_can)
|| (busqueda == result[i].mun_can.toLowerCase())
|| (busqueda == result[i].mun_can)
|| ((busqueda == result[i].nom_can.toLowerCase()+" "+result[i].ape_can.toLowerCase()))
|| ((busqueda == result[i].nom_can+" "+result[i].ape_can))
)
{
text += '<tbody>';
text += '<tr>';
text += '<td>';
text += result[i].ci_can;
text += '</td>';
text += '\t\t';
text += '<td>';
text += result[i].nom_can;
text += ' ';
text += result[i].ape_can;
text += '</td>';
text += '\t\t';
text += '<td>';
text += result[i].fky_cat;
text += '</td>';
text += '\t\t';
text += '<td>';
text += result[i].mun_can;
text += '</td>';
text += '\t\t';
text += '<td>';
text += result[i].est_can;
text += '</td>';
text += '\t\t';
text += '<td>';
text += '</td>';
text += '</tr>';
text += '</tbody>';
}
document.getElementById("find").innerHTML= text;
}
});
}
解决方案
推荐阅读
- c++ - c++ CLI Export void return __declspec(dllexport) 不能应用于具有 __clrcall 调用约定的函数
- apache-spark - log4j 集群模式的日志在哪里写?
- excel - 我如何修复 Lmonth 循环
- ios - 为标签栏中的更多按钮设置图像
- jquery - jQuery ajax 链 - 如何传递响应值
- javascript - document.getElementById('ID') 仅在我的部分代码中返回 null
- arrays - SAS 阵列无法处理一长串变量
- typescript - 使用对象作为字典时如何确保类型安全和详尽?
- javascript - 我被简单的问题阻塞了,无限循环
- amazon-web-services - 使用 terraform 自动扩展 AWS spotfleet 会重置目标容量