为什么点击登录框外的模态登录不关闭?



我已经按如下所示调用了js:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="modal_style.css">
<script src="modal_js.js"></script>
<title>Modal Login Page</title>
</head>
<body>
<h1>Let's get started by</h1>
<button onclick="document.getElementById('id01').style.display='block'" style="width:auto;">Login</button>
<div id="id01" class="modal">
<form class="modal-content animate" action="/action_page.php" method="post">
<div class="imgcontainer">
<span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">&times;</span>

我的JavaScript文件如下:

var modal = document.getElementById('id01');
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}

请帮我找出错误

创建一个div并将logindiv放在里面然后点击第一个div创建两个div

document.getElementById("div1").style.display = "none"
document.getElementById("div2").style.display = "none"

最新更新