Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

171
Vistas
Explicación de la función de búsqueda en javascript

Estoy tratando de dar una breve explicación para este código que he incluido en mi sitio web para buscar en la primera columna de una tabla. Puede alguien ayudarme con esto? No estoy seguro de si esto va en contra de las reglas de stackoverflow, pero lo intentaré. (el código funciona bien)

 function tableSearch(){ let input, filter, table, tr, td, h, txtValue; //Initializing Var input = document.getElementById("myInput"); filter = input.value.toUpperCase(); table = document.getElementById("myTable"); tr = document.getElementsByTagName("tr"); for(let h = 0; h < tr.length; h++){ td = tr[h].getElementsByTagName("td")[0]; if(td){ txtValue = td.textContent || td.innerText; if(txtValue.toUpperCase().indexOf(filter) > -1){ tr[h].style.display = ""; } else { tr[h].style.display = "none"; } } } }

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

function tableSearch(){ let input, filter, table, tr, td, h, txtValue; //Initializing Var input = document.getElementById("myInput"); //find input element filter = input.value.toUpperCase(); //the search value in user's search input table = document.getElementById("myTable"); //don't see anywhere using this variable tr = document.getElementsByTagName("tr"); //get all `tr` (maybe from your table?) //loop through all `tr` for(let h = 0; h < tr.length; h++){ //get only first `td` from the current `tr` (`tr` is based on index) td = tr[h].getElementsByTagName("td")[0]; //if found the first `td` if(td){ //get the first `td` content txtValue = td.textContent || td.innerText; //if the first `td` content matches with your search input //show the entire current `tr` if(txtValue.toUpperCase().indexOf(filter) > -1){ tr[h].style.display = ""; } //if the first `td` content does not with your search input //hide the entire current `tr` else { tr[h].style.display = "none"; } } } }

Una nota al margen aquí que toUpperCase() en el valor de entrada de búsqueda y el contenido td es ignorar mayúsculas y minúsculas

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda