首页 > 解决方案 > 如何使我的搜索功能不区分大小写?

问题描述

我正在做一个 Electron 项目,但我在搜索功能方面遇到问题,我找不到解决方案,希望你能帮助我。

我做了一个简单的搜索功能,其中一个表格填充了结果,它适用于name, lastname, ID,等。但是andemail有一个问题,区分大小写。namelastname

示例 1

示例 2

这是代码:

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;
        }
    });
}

标签: javascriptmysqlelectron

解决方案


推荐阅读