Ich habe eine Schaltfläche erstellt, die ein Fenster öffnet, ich habe es mit einer JavaScript-Funktion gemacht und möchte, dass es geschlossen wird, wenn ich irgendwo anders klicke als auf das Popup-Fenster. Ich habe versucht, dies zu tun, aber es schließt das Pop-up, wenn ich auf das Pop-up selbst klicken bitte helfen!Schließen Sie das Popup, wenn Sie nur auf das Popup klicken?
body{
\t overflow-y:scroll;
\t padding: 0;
\t margin: 0;
}
.wrapper{
\t width: 960px; margin: 40px auto; text-align: left;
}
.popup-position{
\t display: none;
\t position: fixed;
\t top: 0;
\t left: 0;
\t background-color: rgba(0,0,0,0.7);
\t width: 100%;
\t height: 100%;
}
#popup-wrapper{
\t width: 500px;
\t margin: 70px auto;
\t text-align: left;
}
#popup-container{
\t background-color: #FFF;
\t padding: 20px;
\t border-radius: 4px;
}
<!DOCTYPE html>
<html>
<head>
<title>adfadf</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css">
<link href="cdn-images.mailchimp.com/embedcode/classic-10_7.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script type="text/javascript">
<!--
function toggle_visibility(id) {
var e = document.getElementById(id);
if (e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
function closePopup(id) {
var e = document.getElementById(id);
if (e.style.display == 'block')
e.style.display = 'none';
}
//-->
</script>
</head>
<body>
<div id="popup-box1" class="popup-position" onclick="closePopup('popup-box1');">
<div id="popup-wrapper">
<div id="popup-container">
<p><a href="javascript:void(0)" onclick="toggle_visibility('popup-box1');">close</a>
</p>
</div>
</div>
</div>
<div class="wrapper">
<a class="btn btn-primary" href="javascript:void(0)" onclick="toggle_visibility('popup-box1');">Open popup box 1</a>
</div>
</body>
</html>
Nun, Sie eingestellt haben '# Popup-box1' zu schließen auf Klick ... – gcampbell
ich tat es dies nur schließen, wenn ich irgendwo – ssabin