首页 >web前端 >Bootstrap教程 > 正文

bootstrap 模态框用法

原创2021-02-07 09:39:1001325

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

本文操作环境:Windows7系统、bootstrap3、Dell G3电脑。

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>
                <h4 class="modal-title text-center" id="myModalLabel">标题是什么</h4>
            </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 模态框用法的详细内容,更多请关注php中文网其它相关文章!

php中文网最新课程二维码

声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理

  • 相关标签:bootstrap
  • 相关文章

    相关视频


    网友评论

    文明上网理性发言,请遵守 新闻评论服务协议

    我要评论
  • 专题推荐

    推荐视频教程
  • bootstrap项目实战:快速构建响应式网页bootstrap项目实战:快速构建响应式网页
  • bootstrap3系列(英文)+Twitter Bootstrap101系列bootstrap3系列(英文)+Twitter Bootstrap101系列
  • 兄弟连张诚UI教程Bootstrap视频教程兄弟连张诚UI教程Bootstrap视频教程
  • bootstrap框架基础课程bootstrap框架基础课程
  • 视频教程分类