Bootstrap基本插件学习笔记之Alert警告框(20)

2019-11-26,,,,

和前面的模态对话框类似。

0x01 例子

先看一个简单的例子:

<!DOCTYPE html>
<html lang="zh-cn">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <link href="../../css/bootstrap.min.css" rel="stylesheet">
 <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
 <script src="../../js/bootstrap.min.js"></script>
 <title>警告框</title>
</head>
<body>
<div class="container">
 <div class="page-header">
 <h1>警告框</h1>
 </div>
 <div class="alert alert-danger fade in ">
 警告!服务器dang了
 <a href="#" class="close" data-dismiss="alert">×</a>
 </div>
</div>
</body>
</html>

效果如下:

0x02 事件

Alert警告框和模态对话框类似,也支持JS事件:

(1)close.bs.alert

当调用 close 实例方法时立即触发该事件:

$('#myalert').bind('close.bs.alert', function () {
 // 执行一些动作...
})

(2)closed.bs.alert

当警告框被关闭时触发该事件(将等待 CSS 过渡效果完成):

$('#myalert').bind('closed.bs.alert', function () {
 // 执行一些动作...
})

看一个例子:

<!DOCTYPE html>
<html lang="zh-cn">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <link href="../../css/bootstrap.min.css" rel="stylesheet">
 <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
 <script src="../../js/bootstrap.min.js"></script>
 <title>警告框</title>
</head>
<body>
<div class="container">
 <div class="page-header">
 <h1>警告框</h1>
 </div>
 <div class="alert alert-danger fade in" id="myAlert">
 警告!服务器dang了
 <a href="#" class="close" data-dismiss="alert">×</a>
 </div>
</div>
<script>
 $(function () {
 $("#myAlert").bind('closed.bs.alert',function () {
  alert("警告消息框被关闭!");
 });
 })
</script>
</body>
</html>

如果大家还想深入学习,可以点击这里进行学习,再为大家附3个精彩的专题:

Bootstrap学习教程

Bootstrap实战教程

Bootstrap插件使用教程

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持北冥有鱼。

您可能感兴趣的文章:

  • Bootstrap警告框(Alert)插件使用方法
  • Bootstrap笔记之缩略图、警告框实例详解
  • Bootstrap缩略图与警告框学习使用
  • bootstrap警告框使用方法解析
  • Bootstrap每天必学之警告框插件
  • bootstrap警告框示例代码分享

《Bootstrap基本插件学习笔记之Alert警告框(20).doc》

下载本文的Word格式文档,以方便收藏与打印。