我在网页中有 2 个弹出模式,如果用户单击模式之外的任何位置,我想关闭它们。问题是只有第二个有效,第一个无效。
// When the user clicks anywhere outside of the modal1, close it
window.onclick = function(event){
if (event.target == modal1) {
modal1.style.display = "none";
}}
//When the user clicks anywhere outside of the modal2, close it
window.onclick = function(event) {
if (event.target == modal2) {
modal2.style.display = "none";
}}