Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

318
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!