これは、誰かがDivの外部のどこかをクリックして閉じるときにウィンドウを閉じるためのjscriptです。私の質問は、誰かがアクションを実行してこれをクリックしたときにこのウィンドウを閉じることです。
<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を閉じる方法