我有两个弹出式模态在网页上,我想关闭,如果用户点击任何地方以外的模态。问题是,只有第二个有效,第一个不起作用。
// 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";
}}发布于 2017-02-17 13:02:37
你用第二个one.You覆盖了第一个onclick,可以这样做;
window.onclick = function(event){
if (event.target == modal1){modal1.style.display = "none"; }
if (event.target == modal2){modal2.style.display = "none";}
}https://stackoverflow.com/questions/42178199
复制相似问题