使用 onclick 事件 javascript 关闭模态弹出窗口时出错

问题描述 投票:0回答:0

试图处理关闭的弹出窗口。但我有一个错误。问题是否涉及到 rhis 关键字?

https://codesandbox.io/s/tours-test-slick-v1uw96?file=/index.js:626-1309

// Get the modal
const modal = document.getElementById("myModal");

// Get the button that opens the modal
const btn = document.getElementById("myBtn");

// Get the <span> element that closes the modal
const close = document.getElementsByClassName("closeBtn");

// When the user clicks the button, open the modal
btn.onclick = function () {
  modal.style.display = "block";
};

// When the user clicks on <span> (x), close the modal
close.onclick = function () {
  modal.style.display = "none";
};

// When the user clicks anywhere outside of the modal, close it
window.onclick = function (event) {
  if (event.target == this.modal) {
    modal.style.display = "none";
  }
};

javascript css function popup display
© www.soinside.com 2019 - 2024. All rights reserved.