twitter-bootstrap 使用 Twitter Bootstrap 解除警报不起作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13511833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Alert dismissing using Twitter Bootstrap is not working?
提问by Ashraf Bashir
I'm using Google Chrome.
Using Twitter Bootstrap, I want to add a simple alert, unfortunately the alertis not dismissing when the x is pressed!
我正在使用谷歌浏览器。
使用Twitter Bootstrap,我想添加一个简单的警报,不幸的是,当按下 x 时警报不会解除!
Here's my code based on alertdocumentation:
这是我基于警报文档的代码:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
</head>
<body>
<div class="alert">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Warning!</strong> Best check yo self, you're not looking too good.
</div>
</body>
</html>
And I also tried:
我也试过:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
</head>
<body>
<div class="alert">
<a href="#" class="close" data-dismiss="alert">×</a>
<strong>Warning!</strong> Best check yo self, you're not looking too good.
</div>
</body>
</html>
What is missing to make it dismiss ?
缺少什么才能让它解散?
回答by Ashraf Bashir
Thanks to davidkonrad's comment.
The solution is trivial, by adding:
感谢davidkonrad的评论。
解决方案很简单,通过添加:
<script src="js/bootstrap.min.js"></script>
回答by Dave Sag
I've written a small, customisable, jquery pluginthat injects a properly formed Bootstrap 3 alert (with or without close button as you need it) with a minimum of fuss and allows you to easily regenerate it after the box is closed.
我编写了一个小型的、可定制的 jquery 插件,它以最少的麻烦注入了一个正确格式的 Bootstrap 3 警报(根据需要带或不带关闭按钮),并允许您在关闭框后轻松地重新生成它。
See https://github.com/davesag/jquery-bs3Alertfor usage, tests, and examples.
有关用法、测试和示例,请参阅https://github.com/davesag/jquery-bs3Alert。

