我使用本教程将弹出窗口添加到我的网页。有没有一种方法可以使当您单击弹出窗口外部/单击另一个弹出窗口时关闭弹出窗口。
我尝试按照这篇文章Close pop up div by click out of it添加一个无形的Div ,但弹出窗口仍然仅在单击按钮本身时才移动。
https://www.w3schools.com/howto/howto_js_popup.asp
// When the user clicks on div, open the popup
function myFunction() {
var popup = document.getElementById("myPopup");
popup.classList.toggle("show");
}Run Code Online (Sandbox Code Playgroud)
/* 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: 160px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px; …Run Code Online (Sandbox Code Playgroud)