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

201
Visualizações
¿Cómo puedo hacer un botón de aceptar para cada fila de la tabla?

Quiero hacer un botón de aceptar donde cuando presiono el botón de aceptar se muestra otra columna, funcionó bien en la primera fila de la tabla, pero las otras filas no funcionaron.
Aquí está mi código HTML y PHP:

 <tbody> <?php $sql = "SELECT * FROM appointments INNER JOIN patients ON appointments.patientID =patients.patientID WHERE docID='$doctorId'"; $stmt = $conn->prepare($sql); $stmt->execute(); $i=0; while($row = $stmt->fetch(PDO::FETCH_ASSOC)){ $i++; extract($row); echo"<tr> <td >$i</td> <td>{$patientFName} {$patientLName}</td> <td>{$AppStart}</td> <td>{$AppEnd}</td> <td id='refuseAccept' style='display:block;'> <button type='button' class='btn btn-outline-danger'>refuse</button> <button type='button' class='btn btn-outline-success m-2 acceptPpomentDoc' >accept</button> </td> <td id='showOptions' style='display:none; class='m-2' > <a href='#' title='view Details' class='text-success p-2 addappoment' > <i class='fas fa-calendar-check'></i></a> <a href='#' title='Edit' class='text-primary p-2 editBtn' ><i class='fas fa-user-edit'></i> </a> <a href='#' title='Delete' class='text-danger p2 deleteBtn' ><i class='fas fa-user-times'></i> </a> </td> </tr> "; } ?> </tbody>

y aquí está Javascript:

 $(document).on('click','.acceptPpomentDoc', function (){ document.getElementById('showOptions').style.display = "block"; document.getElementById('refuseAccept').style.display = "none"; });
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

No use la misma identificación varias veces. En su lugar, utilice un nombre de clase u otro atributo. Puede hacer referencia a las etiquetas div de destino utilizando rutas relativas, como:

 $(document).on('click', '.acceptPpomentDoc', function() { // $(this) references the item clicked, in this case the accept button $(this).closest('tr').find('.showOptions').show(); // find the containing <tr>, then from there find the div with class name showOptions and set display:block $(this).closest('tr').find('.refuseAccept').hide(); // find the containing <tr>, then from there find the div with class name refuseAccept and set display:none }); 

 $(document).on('click', '.acceptPpomentDoc', function() { $(this).closest('tr').find('.showOptions').show(); $(this).closest('tr').find('.refuseAccept').hide(); });
 .showOptions { display: none; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <table> <tr> <td>$i</td> <td>{$patientFName} {$patientLName}</td> <td>{$AppStart}</td> <td>{$AppEnd}</td> <td class='refuseAccept'> <button type='button' class='btn btn-outline-danger'>refuse</button> <button type='button' class='btn btn-outline-success m-2 acceptPpomentDoc'>accept</button> </td> <td class='showOptions m-2'><strong>ACCEPTED <a href='#' title='view Details' class='text-success p-2 addappoment'> <i class='fas fa-calendar-check'></i></a> <a href='#' title='Edit' class='text-primary p-2 editBtn'><i class='fas fa-user-edit'></i> </a> <a href='#' title='Delete' class='text-danger p2 deleteBtn'><i class='fas fa-user-times'></i> </a> </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