其他分享
首页 > 其他分享> > Bootstrap5 多级dropdown

Bootstrap5 多级dropdown

作者:互联网

<div class="dropdown">
  <a class="btn dropdown-toggle"> Dropdown link </a>
  <ul class="dropdown-menu">
    <div class="dropdown-item dropdown">
      <a class="btn dropdown-toggle"> Dropdown link </a>
      <ul class="dropdown-menu">
        <div class="dropdown-item dropdown">
          <a class="btn dropdown-toggle"> Dropdown link </a>
          <ul class="dropdown-menu">
            <li><a class="dropdown-item">Action</a></li>
            <li><a class="dropdown-item">Another action</a></li>
            <li>
              <a class="dropdown-item">Something else here</a>
            </li>
          </ul>
        </div>
      </ul>
    </div>
  </ul>
</div>
document.querySelectorAll('.dropdown .dropdown-toggle').forEach((a) => {
  let dropdown: bootstrap.Dropdown;
  a.addEventListener('click', (e) => {
    const show = a.classList.contains('show');
    if (show) {
      a.classList.remove('show');
      dropdown.hide();
    } else {
      a.setAttribute('data-bs-toggle', 'dropdown');
      dropdown.show();
      a.removeAttribute('data-bs-toggle');
    }
  });
  dropdown = new bootstrap.Dropdown(a);
});
.dropdown.dropdown-item:active {
  background-color: inherit;
}

标签:show,多级,Dropdown,toggle,link,bs,Bootstrap5,dropdown
来源: https://www.cnblogs.com/ajanuw/p/14334239.html