bootstrap模态框的使用案例

发布时间:2021-02-12 18:10:13 作者:小新
来源:亿速云 阅读:206

小编给大家分享一下bootstrap模态框的使用案例,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

bootstrap模态框的用法:1、通过data属性,同时设置“data-target="#myModal"”选择器内容;2、通过js,直接用代码“$(’#myModal’).modal(options)”等等。

bootstrap的模态框

如果只想单独使用模态框功能,可以单独引入modal.js,和bootstrap的css,在bootstrap的包中,可引入bootstrap.js。

用法

  1. 通过data属性,比如设置某个butto的data-toggle=’“modal”,同时设置 data-target="#myModal" 选择器内容,

  2. 通过js直接用代码 $(’#myModal’).modal(options)

  3. 模态框主要为三部分,model-head,modeal-body,model-footer,主要内容在body中显示,class="close"为一个关闭模态框样式。

  4. 几个常用的方法 $(’#identifier’).modal(‘toggle’) 切换模态框状态

    $(’#identifier’).modal(‘show’) 显示模态框

    $(’#identifier’).modal(‘hide’) 隐藏模态框

事件作用用法
show.bs.modal在调用 show 方法后触发。$(’#myModal’).on(‘show.bs.modal’,function () {alert(“显示模态框”);});
shown.bs.modal在调用 show 方法后触发。$(’#myModal’).on(‘shown.bs.modal’, function () {alert(“完全显示模态框”); });
hide.bs.modal在调用 hide  方法后触发。$(’#myModal’).on(‘hide.bs.modal’, function () {alert(“隐藏模态框”);});
hidden.bs.modal在调用 hide  方法后触发。$(’#myModal’).on(‘hidden.bs.modal’, function () {alert(“完全隐藏模态框”); });

使用步骤两步

1、按顺序引入以下三个文件(推荐:《bootstrap教程》)

<link rel="stylesheet" href="../css/bootstrap.min.css">
<script sype="text/JavaScript" src="./jquery.min.js"></script>
<script sype="text/JavaScript" src="../js/bootstrap.min.js"></script>

2、在页面中copy下面的代码

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">开始演示模态框</button>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h5 class="modal-title text-center" id="myModalLabel">标题是什么</h5>
            </div>
            <div class="modal-body">
                写你HTML文本
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary">保存添加</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

简单吧,模态框就是需要一个触发,在触发模态框的html元素加入以下属性data-toggle="modal" data-target="#myModal"

观察以下就会发现 这个data-target="#myModal"中的myModal就是模态框所在div的id <div class="modal fade" id="myModal".............>

看完了这篇文章,相信你对“bootstrap模态框的使用案例”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

推荐阅读:
  1. bootstrap 模态框
  2. bootstrap-模态框

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

bootstrap

上一篇:html头文件css的写法

下一篇:如何在Linux中部署一个.net core Api项目

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》