如何使用jQuery调用Bootstrap alert
How to call Bootstrap alert with jQuery?
假设我有以下一段代码:
<div class="alert alert-info fade in" id="bsalert">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Info!</strong> This alert box could indicate a neutral informative or action
</div>
如何使用jQuery手动激活它?
Bootstrap使用in
和out
类来实现可见性。你只需要切换这些类。此外,如果您想在取消后保持警报,您可以向close.bs.alert
事件添加返回false。
function toggleAlert(){
$(".alert").toggleClass('in out');
return false; // Keep close.bs.alert event from removing from DOM
}
$("#btn").on("click", toggleAlert);
$('#bsalert').on('close.bs.alert', toggleAlert)
<link rel="stylesheet" type="text/css" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<button id="btn">Toggle</button>
<div class="alert alert-info fade out" id="bsalert">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Info!</strong> This alert box could indicate a neutral informative or action
</div>
<div>
content
相关文章:
- 如何在Bootstrap Modal中为动态点击生成的变量设置jade属性
- 浮动页脚栏-使用Bootstrap隐藏
- Twitter Bootstrap typeahead:使用“this”获取上下文/调用元素
- 创建带有和不带有JavaScript的Bootstrap下拉菜单
- AngularJS/HTML/Bootstrap元素用于动态搜索结果
- Javascript+Bootstrap图像库未加载
- Bootstrap Dropdown selection是在*all*下拉菜单上设置选择
- Bootstrap 3 Datepicker v4:dp.show和dp.change事件在Datepicker内联时不
- Bootstrap-三列相等;t更改'a'要素
- 在bootstrap中显示隐藏特定的li
- 为什么引导程序下拉菜单只有在包含bootstrap-responsive.css时才起作用
- Twitter Bootstrap 2.1.0子菜单在Responsive上看起来很混乱
- Bootstrap Alert只显示一次
- AngularJS + Bootstrap dismissable alert
- 在javascript中遇到有关bootstrap-alert.js的错误
- 关闭Bootstrap Alert之前请遵循链接
- Bootstrap Alert会在.hide()之后的.show()之间切换
- 如何使用jQuery调用Bootstrap alert
- 如何将Bootstrap 3模式用于JavaScript alert()
- 每次打开Bootstrap模式时执行alert(),不工作