Bootstrap 5 下拉切换不起作用,不知道为什么?
Bootstrap 5 dropdown toggle not working, cant figure out why?
<div className="dropdown">
<a
className="dropdown-toggle d-flex align-items-center hidden-arrow"
href="#"
id="navbarDropdownMenuAvatar"
role="button"
data-mdb-toggle="dropdown"
aria-expanded="false">
<img
src="https://mdbcdn.b-cdn.net/img/new/avatars/2.webp"
className="rounded-circle"
height="50"
alt="Black and White Portrait of a Man"
loading="lazy"
/>
</a>
<ul
className="dropdown-menu dropdown-menu-end"
aria-labelledby="navbarDropdownMenuAvatar">
<li>
<a className="dropdown-item" href="#">
My profile
</a>
</li>
<li>
<a className="dropdown-item" href="#">
Settings
</a>
</li>
<li>
<a className="dropdown-item" href="#">
Logout
</a>
</li>
</ul>
</div>
单击图像(下拉切换)时没有任何反应。我也包含了 JS 文件,css 渲染正常,但切换不工作并且没有显示下拉项:
src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"
将data-mdb-toggle
替换为data-bs-toggle
d-flex
和 d-inline-flex
在正确的位置打开菜单。
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous"
/>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"
>
</script>
<div class="dropdown">
<a
class="dropdown-toggle d-inline-flex align-items-center hidden-arrow"
href="#"
id="navbarDropdownMenuAvatar"
role="button"
data-bs-toggle="dropdown"
aria-expanded="false"
>
<img
src="https://mdbcdn.b-cdn.net/img/new/avatars/2.webp"
class="rounded-circle"
height="50"
alt="Black and White Portrait of a Man"
loading="lazy"
/>
</a>
<ul
class="dropdown-menu dropdown-menu-end"
aria-labelledby="navbarDropdownMenuAvatar"
>
<li>
<a class="dropdown-item" href="#">
My profile
</a>
</li>
<li>
<a class="dropdown-item" href="#">
Settings
</a>
</li>
<li>
<a class="dropdown-item" href="#">
Logout
</a>
</li>
</ul>
</div>
更多:
Bootstrap v5 文档:https://getbootstrap.com/docs/5.0/components/dropdowns/#examples
<div className="dropdown">
<a
className="dropdown-toggle d-flex align-items-center hidden-arrow"
href="#"
id="navbarDropdownMenuAvatar"
role="button"
data-mdb-toggle="dropdown"
aria-expanded="false">
<img
src="https://mdbcdn.b-cdn.net/img/new/avatars/2.webp"
className="rounded-circle"
height="50"
alt="Black and White Portrait of a Man"
loading="lazy"
/>
</a>
<ul
className="dropdown-menu dropdown-menu-end"
aria-labelledby="navbarDropdownMenuAvatar">
<li>
<a className="dropdown-item" href="#">
My profile
</a>
</li>
<li>
<a className="dropdown-item" href="#">
Settings
</a>
</li>
<li>
<a className="dropdown-item" href="#">
Logout
</a>
</li>
</ul>
</div>
单击图像(下拉切换)时没有任何反应。我也包含了 JS 文件,css 渲染正常,但切换不工作并且没有显示下拉项:
src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"
将data-mdb-toggle
替换为data-bs-toggle
d-flex
和 d-inline-flex
在正确的位置打开菜单。
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous"
/>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"
>
</script>
<div class="dropdown">
<a
class="dropdown-toggle d-inline-flex align-items-center hidden-arrow"
href="#"
id="navbarDropdownMenuAvatar"
role="button"
data-bs-toggle="dropdown"
aria-expanded="false"
>
<img
src="https://mdbcdn.b-cdn.net/img/new/avatars/2.webp"
class="rounded-circle"
height="50"
alt="Black and White Portrait of a Man"
loading="lazy"
/>
</a>
<ul
class="dropdown-menu dropdown-menu-end"
aria-labelledby="navbarDropdownMenuAvatar"
>
<li>
<a class="dropdown-item" href="#">
My profile
</a>
</li>
<li>
<a class="dropdown-item" href="#">
Settings
</a>
</li>
<li>
<a class="dropdown-item" href="#">
Logout
</a>
</li>
</ul>
</div>
更多:
Bootstrap v5 文档:https://getbootstrap.com/docs/5.0/components/dropdowns/#examples