Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

263
Visualizações
¿Cómo buscar el número de la tabla html usando javascript?

Tengo dificultades para buscar números en la tabla HTML usando javascript. Lo que quiero hacer, si ingreso 500, los resultados deberían ser 500 y números que también son mayores que 500. Revisé otras preguntas de StackOverflow pero no se responde como esperaba. ¿Alguien puede ayudarme, por favor?

 function myFunction(){ let filter = document.getElementById('myInput').value; let myTable = document.getElementById('myTable'); let tr = myTable.getElementsByTagName('tr'); for(var i=0; i<tr.length; i++) { let td = tr[i].getElementsByTagName('td')[0]; if(td) { let textValue = td.textContent || td.innerHTML; if(textValue >= filter ) { tr[i].style.display = ""; } else { tr[i].style.display = "none"; } } } }
 <input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names.." title="Type in a name"> <table id="myTable"> <tr class="header"> <th style="width:60%;">Number</th> <th style="width:40%;">Alphabats Code</th> </tr> <tr> <td>500</td> <td>ANAA</td> </tr> <tr> <td>520</td> <td>MNAAA</td> </tr> <tr> <td>400</td> <td>INNA</td> </tr> <tr> <td>200</td> <td>OISSS</td> </tr> <tr> <td>500</td> <td>QIIWS</td> </tr> </table>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Un pequeño cambio en tu código.

 if(+textValue >= +filter )

Comparar valores como número en lugar de cadenas

 function myFunction(){ let filter = document.getElementById('myInput').value; let myTable = document.getElementById('myTable'); let tr = myTable.getElementsByTagName('tr'); for(var i=0; i<tr.length; i++) { let td = tr[i].getElementsByTagName('td')[0]; if(td) { let textValue = td.textContent || td.innerHTML; if(+textValue >= +filter ) { tr[i].style.display = ""; } else { tr[i].style.display = "none"; } } } }
 <input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names.." title="Type in a name"> <table id="myTable"> <tr class="header"> <th style="width:60%;">Number</th> <th style="width:40%;">Alphabats Code</th> </tr> <tr> <td>500</td> <td>ANAA</td> </tr> <tr> <td>520</td> <td>MNAAA</td> </tr> <tr> <td>400</td> <td>INNA</td> </tr> <tr> <td>200</td> <td>OISSS</td> </tr> <tr> <td>500</td> <td>QIIWS</td> </tr> </table>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda