这是一个 jscript,用于在有人单击 Div 以外的任何位置关闭窗口时关闭窗口。我的问题是当有人通过执行操作单击此窗口时关闭此窗口。
<div id="box"
style="height: 3em; position:absolute; top: 20%; left: 15%; border: 3px double">
<p>Click anywhere outside this box to close it.
</div>
<script>
document.onclick = function (e) {
e = e || event
var target = e.target || e.srcElement
var box = document.getElementById("box")
do {
if (box == target) {
// Click occured inside the box, do nothing.
return
}
target = target.parentNode
} while (target)
// Click was outside the box, hide it.
box.style.display = "none"
}
</script>
如何在 DIV 内发生单击时关闭 Div