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

334
Visualizações
No cierre la ventana emergente de CSS al hacer clic en ella

Estoy tratando de agregar un formulario dentro de una ventana emergente, pero cada vez que hace clic en el cuadro de texto en la ventana emergente, se cierra y no puede escribir en el cuadro de texto, ¿hay alguna forma de desactivar el clic para cerrar? y solo haga que haga clic en la ventana emergente que se cierra en lugar de dentro de la ventana emergente. Intenté cambiar el CSS de myPopup y agregué 'pointer-events: none' pero eso deshabilita hacer clic en todos los componentes dentro de la ventana emergente.

 // When the user clicks on div, open the popup function myFunction() { var popup = document.getElementById("myPopup"); popup.classList.toggle("show"); }
 /* Popup container - can be anything you want */ .popup { position: relative; display: inline-block; cursor: pointer; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } /* The actual popup */ .popup .popuptext { visibility: hidden; width: 180px; background-color: #555; color: #fff; text-align: center; border-radius: 6px; padding: 8px 0; position: absolute; z-index: 1; bottom: 125%; left: 50%; margin-left: -80px; height: 200px; } /* Popup arrow */ .popup .popuptext::after { content: ""; position: absolute; top: 100%; left: 50%; margin-left: -5px; border-width: 5px; border-style: solid; border-color: #555 transparent transparent transparent; } /* Toggle this class - hide and show the popup */ .popup .show { visibility: visible; -webkit-animation: fadeIn 1s; animation: fadeIn 1s; } /* Add animation (fade in the popup) */ @-webkit-keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } } @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
 <body style="text-align:center"> <h2>Popup</h2> <br><br><br><br><br><br><br><br><br><br><br><br> <div class="popup" onclick="myFunction()">Click me to toggle the popup! <span class="popuptext" id="myPopup"><input type="text" id="fname" name="fname"><br><br> <button> <button></span> </div>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Es porque todo su div y todo lo que contiene está siendo activado por onclick . Cree un botón con la función onclick y utilícelo para activar la apertura y el cierre de la ventana emergente.

Además, considere usar un eventListener en lugar del onclick en línea, ya que generalmente se desaconseja.

https://www.w3schools.com/jsref/met_element_addeventlistener.asp

Lo cual podría escribirse como:

 const element = document.getElementById("myBtn"); element.addEventListener("click", function() { var popup = document.getElementById("myPopup"); popup.classList.toggle("show"); }); 

 // When the user clicks on div, open the popup function myFunction() { var popup = document.getElementById("myPopup"); popup.classList.toggle("show"); }
 /* Popup container - can be anything you want */ .popup { position: relative; display: inline-block; cursor: pointer; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } /* The actual popup */ .popup .popuptext { visibility: hidden; width: 180px; background-color: #555; color: #fff; text-align: center; border-radius: 6px; padding: 8px 0; position: absolute; z-index: 1; bottom: 125%; left: 50%; margin-left: -80px; height: 200px; } /* Popup arrow */ .popup .popuptext::after { content: ""; position: absolute; top: 100%; left: 50%; margin-left: -5px; border-width: 5px; border-style: solid; border-color: #555 transparent transparent transparent; } /* Toggle this class - hide and show the popup */ .popup .show { visibility: visible; -webkit-animation: fadeIn 1s; animation: fadeIn 1s; } /* Add animation (fade in the popup) */ @-webkit-keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } } @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
 <body style="text-align:center"> <h2>Popup</h2> <br><br><br><br><br><br><br><br><br><br><br><br> <div class="popup"> <span class="popuptext" id="myPopup"><input type="text" id="fname" name="fname"><br><br> </span> <button onclick="myFunction()"> Click me to toggle the popup! </button> </div> </body>

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