Bootstrap 4 - 切换按钮不起作用 [英] Bootstrap 4 - Toggle button not working
本文介绍了Bootstrap 4 - 切换按钮不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将 navbar
添加到我的网站,但是当我添加它时,切换按钮不起作用。
这是我的 navbar
代码:
< nav class =navbar navbar-expand-lg navbar-light bg-light>
< a class =navbar-brandhref =#> Navbar< / a>
< span class =navbar-toggler-icon>< / span>
< / button>
< div class =collapse navbar-collapseid =navbarSupportedContent>
< ul class =navbar-nav mr-auto>
< li class =nav-item active>
< a class =nav-linkhref =#>主页< span class =sr-only>(current)< / span>< / a>
< / li>
< li class =nav-item>
< a class =nav-linkhref =#>连结< / a>
< / li>
< li class =nav-item>
< a class =nav-link disabledhref =#>已禁用< / a>
< / li>
< / ul>
< form class =form-inline my-2 my-lg-0>
< input class =form-control mr-sm-2type =textplaceholder =Searcharia-label =Search>
< button class =btn btn-outline-success my-2 my-sm-0type =submit>搜索< / button>
< / form>
< / div>
< / nav>
以下是我包含的内容:
< link rel =stylesheethref =https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.cssintegrity = sha384- / Y6pD6FV / Vv2HJnA6t + vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6Mcrossorigin =anonymous>
< script src =https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.jsintegrity =sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1crossorigin =anonymous> < /脚本>
< script src =https://code.jquery.com/jquery-3.2.1.slim.min.jsintegrity =sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr / rE9 / Qpg6aAZGJwFDMVNA / GpGFF93hXpG5KkNcrossorigin =anonymous >< /脚本>
< script src =https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.jsintegrity =sha384-b / U6ypiBEHpOf / 4 + 1nzFpr53nxSS + GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4crossorigin =anonymous>< / script>
感谢您的帮助!
解决方案
$ b
您需要输入: -
< script src =https:// code。 jquery.com/jquery-3.2.1.slim.min.jsintegrity =sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr / rE9 / Qpg6aAZGJwFDMVNA / GpGFF93hXpG5KkNcrossorigin =anonymous>< / script>
在所有其他 js
文件之前。
然后它就可以工作了。
工作示例: - https://jsfiddle.net/mmqhw26j/
$ b
注意: - 注意总是需要首先添加jQuery核心库/基础库,然后才需要添加任何其他jQuery文件/库
I'm trying to add navbar
to my website, but when I add it toggle button doesn't work.
Here is my navbar
code:
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
Here is what I've included:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
Thanks for help!
解决方案
You need to put:-
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
Before all the other js
files.
Then it will work.
Working example:- https://jsfiddle.net/mmqhw26j/
Note:- Take care that always jQuery core-library/base-library need to be added first and then only any other jQuery file/library need to add
这篇关于Bootstrap 4 - 切换按钮不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文