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

351
Visualizações
¿Cómo puedo establecer una identificación única en la tabla? JS

Este es el código que tengo (no el mío de Internet) Ahora quiero agregar alguna opción que cuando se crea la celda, quiero agregar una identificación única a cada celda, y luego al hacer clic en alguna celda podré ver esa identificación. ¿Cómo puedo hacer esto?

 <!DOCTYPE html> <html> <head> <title>Chess board</title> <style> body { text-align: center; } .cell { height: 30px; width: 30px; border: 1.5px solid grey; border-style: inset; } .blackcell { background-color: black; } .whitecell { background-color: white; } </style> </head> <body> <script type="text/javascript"> var center = document.createElement('center'); var ChessTable = document.createElement('table'); for (var i = 0; i < 8; i++) { var tr = document.createElement('tr'); for (var j = 0; j < 8; j++) { var td = document.createElement('td'); if ((i + j) % 2 == 0) { td.setAttribute('class', 'cell whitecell'); tr.appendChild(td); } else { td.setAttribute('class', 'cell blackcell'); tr.appendChild(td); } } ChessTable.appendChild(tr); } center.appendChild(ChessTable); ChessTable.setAttribute('cellspacing', '0'); ChessTable.setAttribute('width', '270px'); document.body.appendChild(center); </script> </body> </html>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

 var center = document.createElement('center'); var ChessTable = document.createElement('table'); for (var i = 0; i < 8; i++) { var tr = document.createElement('tr'); for (var j = 0; j < 8; j++) { var td = document.createElement('td'); td.setAttribute('id','cell'+i+'_'+j) td.addEventListener('click',e=>console.log(e.target.id)) if ((i + j) % 2 == 0) { td.setAttribute('class', 'cell whitecell'); tr.appendChild(td); } else { td.setAttribute('class', 'cell blackcell'); tr.appendChild(td); } } ChessTable.appendChild(tr); } center.appendChild(ChessTable); ChessTable.setAttribute('cellspacing', '0'); ChessTable.setAttribute('width', '270px'); document.body.appendChild(center);
 <!DOCTYPE html> <html> <head> <title>Chess board</title> <style> body { text-align: center; } .cell { height: 30px; width: 30px; border: 1.5px solid grey; border-style: inset; } .blackcell { background-color: black; } .whitecell { background-color: white; } </style> </head> <body> </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