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

225
Visualizações
Cómo obtener este JavaScript de entrada para marcar la casilla de verificación por fila de una tabla

Quiero tener una página web con una tabla larga llena de valores de entrada. Quiero marcar una casilla de verificación cuando se modifica un valor de entrada de fila individual. No he podido hacer funcionar la parte de JavaScript.

El siguiente es mi intento

 <!DOCTYPE html> <html> <head> <style>table {border: 1px solid black;} </style> </head> <body> <div class="container"> <form action="" method='POST'> <table id="table" class="table"> <thead> <tr> <th data-type="number">No.</th> <th>First name</th> <th>Modified <br>"to be hidden"</th> </tr> </thead> <tr> <td><input name="no[]" value="1" oninput="mod(this)"></td> <td><input name="f[]" value="Andrea" oninput="mod(this)"></td> <td><input id="modcheck" type="checkbox" name="modify[]" value=""></td> </tr> <tr> <td><input name="no[]" value="2" oninput="mod(this)"></td> <td><input name="f[]" value="Peter" oninput="mod(this)"></td> <td><input id="modcheck" type="checkbox" name="modify[]" value=""></td> </tr> <tr> <td><input name="no[]" value="3" oninput="mod(this)"></td> <td><input name="f[]" value="Sarah" oninput="mod(this)"></td> <td><input id="modcheck" type="checkbox" name="modify[]" value=""></td> </tr> </table> </form> </div> <script> function mod(r) { var i = r.parentNode.parentNode.rowIndex; document.getElementById("modcheck").modifed(i).checked = true; } </script> </body> </html>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Puede iterar sobre cada fila y oninput una función de entrada para marcar la casilla de verificación correspondiente cuando se modifica el cuadro de texto input .

 let rows = document.querySelectorAll("tr"); rows.forEach(row=>{ row.querySelectorAll("input:not(#modcheck)").forEach(input=>{ input.oninput = (e)=>{ row.querySelector("#modcheck").checked = true; } }) })
 <!DOCTYPE html> <html> <head> <style> table { border: 1px solid black; } </style> </head> <body> <div class="container"> <form action="" method='POST'> <table id="table" class="table"> <thead> <tr> <th data-type="number">No.</th> <th>First name</th> <th>Modified <br>"to be hidden"</th> </tr> </thead> <tr> <td><input name="no[]" value="1"></td> <td><input name="f[]" value="Andrea"></td> <td><input id="modcheck" type="checkbox" name="modify[]" value=""></td> </tr> <tr> <td><input name="no[]" value="2"></td> <td><input name="f[]" value="Peter"></td> <td><input id="modcheck" type="checkbox" name="modify[]" value=""></td> </tr> <tr> <td><input name="no[]" value="3"></td> <td><input name="f[]" value="Sarah"></td> <td><input id="modcheck" type="checkbox" name="modify[]" value=""></td> </tr> </table> </form> </div> </body> </html>

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