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

163
Vistas
Asigna el valor de cada td en la tabla con un número único aleatorio con Javascript

Tengo una función que puede generar un número aleatorio único, el resultado se almacena en una matriz. mi pregunta. ¿Cómo se puede ingresar cada número en las filas td cuando hay un evento de clic?

 function random(max, min) { arr = []; for (i = 0; i < max; i++) { x = Math.floor(Math.random() * max) + min; if (arr.includes(x) == true) { i = i - 1; } else { if (x > max == false) { arr.push(x); } } } return arr; }

Por ejemplo, tengo una tabla que tiene 3 filas

 <button class="btn btn-md btn-danger" id="shuffle">Loop</button> <table class="table"> <thead> <tr> <th scope="col">#</th> <th scope="col">First</th> <th scope="col">Last</th> <th scope="col">Number</th> </tr> </thead> <tbody> <tr> <th scope="row">1</th> <td>Mark</td> <td>Otto</td> <td name="random"></td> </tr> <tr> <th scope="row">2</th> <td>Jacob</td> <td>Thornton</td> <td name="random"></td> </tr> <tr> <th scope="row">3</th> <td>Larry</td> <td>the Bird</td> <td name="random"></td> </tr> </tbody> </table>

Y el código de activación

 $('#shuffle').on('click', function (e) { var td = $('td[name="random"]'); td.each((key, value) => { value.value = random(3, 1); // this's just example }); });
about 4 years ago · Juan Pablo Isaza
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