📌  相关文章
📜  如何删除 document.getElementById("myDropdown").classList.toggle("show"); - 无论代码示例

📅  最后修改于: 2022-03-11 14:59:22.100000             🧑  作者: Mango

代码示例1
function myFunction() {
  document.getElementById("myDropdown2").classList.remove("show");
  document.getElementById("myDropdown").classList.toggle("show");
}

function myFunction2() {
  document.getElementById("myDropdown").classList.remove("show");
  document.getElementById("myDropdown2").classList.toggle("show");
}

// Close the dropdown menu if the user clicks outside of it
window.onclick = function(event) {
  if (!event.target.matches('.dropbtn')) {
    var dropdowns = document.getElementsByClassName("dropdown-content");
    var i;
    for (i = 0; i < dropdowns.length; i++) {
      var openDropdown = dropdowns[i];
      if (openDropdown.classList.contains('show')) {
        openDropdown.classList.remove('show');

      }
    }
  }
}