bootstrap模态框的用法是什么?

bootstrap模态框怎么用?下面本篇文章给大家介绍一下bootstrap模态框的使用。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

bootstrap的模态框

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

用法

  1. 通过data属性,比如设置某个button的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(“完全隐藏模态框”); });

实例代码

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <title>shiro</title>
    
        <script type="text/javascript" src="js/jquery-3.3.1.js"></script>
    
    
    
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    
        <script src="https://cdn.bootcss.com/jquery/3.4.1/core.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    
    
        <script type="text/javascript">
            var basePath = "${pageContext.request.contextPath}";
        </script>
    </head>
    <body>
    
    <div>
    
    
        <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
            开始演示模态框
        </button>
        <!-- 模态框(Modal) -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div>
                <div>
                    <div>
                        <button type="button" data-dismiss="modal" aria-hidden="true">
                            &times;
                        </button>
                        <h4 id="myModalLabel">
                            模态框(Modal)标题
                        </h4>
                    </div>
                    <div>
                        <div>我是模态框</div>
                    </div>
                    <div>
                        <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>
    
    
    </div>
    
    
    </body>
    <script type="text/javascript">
    
    
    
        $('#myModal').on('show.bs.modal', function () {
            alert("显示模态框");
        });
    
        $('#myModal').on('shown.bs.modal', function () {
            alert("完全显示模态框");
        });
    
        $('#myModal').on('hide.bs.modal', function () {
            alert("隐藏模态框");
        });
    
        $('#myModal').on('hidden.bs.modal', function () {
            alert("完全隐藏模态框");
        });
    
    
    </script>
    
    </html>

更多bootstrap的相关知识,可访问:web前端自学!!

以上就是bootstrap模态框的用法是什么?的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » Bootstrap 教程