简体   繁体   English

为什么 Bootstrap 4 切换按钮不起作用?

[英]Why Bootstrap 4 Toggle button is not working?

I am working with Laravel 5.8 and Bootstrap 4. I have been installed Bootstrap via npm with the Laravel project and I have following toggle button in the blade file我正在使用 Laravel 5.8 和 Bootstrap 4。我已经通过 npm 和 Laravel 项目安装了 Bootstrap,并且我在刀片文件中具有以下切换按钮

 <button class="btn btn-primary" id="menu-toggle">Toggle Menu</button>

    <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>

and following jquery code to work above toggle button并按照 jquery 代码在切换按钮上方工作

<script>
$("#menu-toggle").click(function(e) {
  e.preventDefault();
  $("#wrapper").toggleClass("toggled");
});
</script>

but when clicked the toggle button here it is not working.但是当单击此处的切换按钮时,它不起作用。 how to fix this problem?如何解决这个问题?

Make sure you have jQuery file above all js files even bootstrap ones.确保 jQuery 文件高于所有 js 文件,甚至是引导文件。

Paste this code before all js files.将此代码粘贴到所有 js 文件之前。

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>

Now it should work Note:- Take care that jQuery core-library/base-library need to be added first and then only any other jQuery file/library can be added.现在它应该可以工作了注意: - 注意需要先添加 jQuery 核心库/基础库,然后才能添加任何其他 jQuery 文件/库。 All other bootstrap js files are dependent on jQuery so it should be imported first.所有其他引导 js 文件都依赖于 jQuery,因此应首先导入。

Also if its still not working then check out if there is any error in your code or not.此外,如果它仍然无法正常工作,请检查您的代码中是否有任何错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM