首页 技术 正文
技术 2022年11月15日
0 收藏 571 点赞 3,622 浏览 1125 个字

Bootstrap入门(三十)JS插件7:警告框

通过这个插件可以为警告信息添加点击以及消失的功能。

当使用一个.close按钮,它必须是第一个子元素.alert-dismissible,并没有文字内容。

1.实例

首先,引入CSS文件和JS文件

<link href="bootstrap.min.css" rel="external nofollow"  rel="stylesheet">
<script src="jquery-3.1.0.min.js" type="text/javascript"></script>
<script src="bootstrap.min.js" type="text/javascript"></script>

创建一个容器div,在里面创建一个承载div,class为alert,样式为alert-info,由于有动态效果,还要有fade in,为了方便使用,添加一个属于他的id

然后再创建一个关闭按钮

最后是文本内容

        <div class="container">
<div class="alert alert-info fade in" id="myalert">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<strong>hello world!</strong>
</div>
</div>

效果,点击之后关闭,而且是有一个动态渐变消失的效果

Bootstrap入门(三十)JS插件7:警告框

2。嵌入按钮

其实里面还可以承载更多东西,比如button按钮

为了对比,在alert的承载div下面我们在创建一个新的div

添加代码

            <div class="alert alert-info fade in" id="myalert2">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<strong>hello world!</strong>
<button type="button" class="btn btn-primary">点击关闭</button>
</div>

效果:

Bootstrap入门(三十)JS插件7:警告框

3.添加JS代码

有时候我们是想直接关闭这个警告框

可以添加代码

        <script>
$("#myalert").alert("close");
</script>

效果是打开页面之后,第一次创建的警告框消失了,只看到第二个

Bootstrap入门(三十)JS插件7:警告框

修改一下代码,用第二个作为实例

            $("#myalert2").on("close.bs.alert",function(e){
console.log("hello world!");
})

打开网页后,先右键,检查,然后选择console,在点击关闭按钮之后,console界面出现“hello world!”

Bootstrap入门(三十)JS插件7:警告框

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,967
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,487
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,332
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,115
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,748
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,783