📌  相关文章
📜  检测元素外部(或内部)的点击 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:43.035000             🧑  作者: Mango

代码示例1
window.addEventListener('mousedown', e => {
  // Get the element that was clicked
  const clickedEl = e.target;

  // `el` is the element you're detecting clicks outside of
  if (el.contains(clickedEl)) {
    // Clicked inside of `el`
  } else {
    // Clicked outside of `el`
  }
});