简体   繁体   English

Bootstrap Alerts Data-Dismiss 不起作用

[英]Bootstrap Alerts Data-Dismiss not working

<div class="alert alert-info alert-dismissible fade show">
  <button class="close" data-dismiss="alert" aria-label="Close">x</button>
  Signed out successfully.
</div>

I can't get my Bootstrap alert to close with the html above.我无法使用上面的 html 关闭我的 Bootstrap 警报。 Everything looks right according to the bootstrap docs.根据引导文档,一切看起来都是正确的。 I'm using this with a rails app.我将其与 Rails 应用程序一起使用。

Can you see what I'm doing wrong?你能看出我做错了什么吗? If nothing is wrong with the HTML, can you offer any ideas.如果HTML没问题,能不能给点意见。 I'm using Rails 5 and Turbolinks 4. I can tell you that bootstrap JS and CSS are both loaded correctly.我正在使用 Rails 5 和 Turbolinks 4。我可以告诉你,bootstrap JS 和 CSS 都已正确加载。

If it does not really work after the solution above, please check if you linked bootstrap javascript functionality links properly at HTML side.如果在上述解决方案后它确实不起作用,请检查您是否在 HTML 端正确链接了 bootstrap javascript 功能链接。 You can check inBootstrap official docs but as of the date of 23 Feb, 2022, I imported proper tags like below;您可以查看Bootstrap 官方文档,但截至 2022 年 2 月 23 日,我导入了如下所示的正确标签;

<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://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

If you import those tags in your HTML file and if you added proper classes to your tags, it should have work.如果您在 HTML 文件中导入这些标签,并且向标签添加了适当的类,它应该可以工作。

PS: If I have any mistakes about answering, sorry that's my first attempt to answer a question. PS:如果我回答有任何错误,抱歉,这是我第一次尝试回答问题。 I'm just a beginner in JavaScript and I really wanted to help beginner folks like me:)我只是 JavaScript 的初学者,我真的很想帮助像我这样的初学者:)

I can't see anything wrong with your HTML mark-up . 我看不到您的HTML mark-up任何问题。

So, it leaves me with one thought, I think you are doing something wrong with the fade show events. 所以,这让我有一个想法,我认为您在fade show事件中做错了什么。 See if you are doing something with those events which is coming into the path of alert close event. 查看您是否正在处理即将进入警报关闭事件路径的那些事件。

Post your javascript, then this only answer can be completed. 发布您的JavaScript,然后可以完成此唯一答案。

You have to add both the fade and in classes to the alert. 你必须同时添加fade ,并in类的警报。

To have your alerts use animation when closing, make sure they have the .fade and .in classes already applied to them. 要使警报在关闭时使用动画,请确保它们已经应用了.fade.in类。

See Alert.js Usage from the Docs. 请参阅文档中的Alert.js 使用情况

This the CSS that's being applied: 这是正在应用的CSS:

.fade.in {
  opacity: 1
}

.fade {
  opacity: 0;
  -webkit-transition: opacity .15s linear;
  -o-transition: opacity .15s linear;
  transition: opacity .15s linear
}

Working Example: 工作示例:

 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" /> <div class="alert alert-info alert-dismissible fade in" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span> </button> Signed out successfully </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 

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

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