Bootstrap 使用对话框

使用模态框的弹窗组件须要三层 div 容器元素javascript

分别为 modal(模态声明层) dialog(窗口声明层) content(内容层)css

在内容层里面,还有三层,分别为 header(头部) body(主体) footer(注脚)html

 

一个简单的对话框登录/注册例子java

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="./css/bootstrap.min.css">
    <script src="./js/jquery.min.js"></script>
    <script src="./js/bootstrap.min.js"></script>
    <style>
        .modal-dialog {
            width: 20%;
        }

        .modal-footer, .modal-header {
            text-align: center;
        }

        input {
            width: 80%;
        }

    </style>
</head>
<body>
    <!-- LOGIN MODULE -->
    <div id="loginModal" class="modal fade" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span>&times;</span>
                    </button>
                    <h4 class="modal-title">会员登陆</h4>
                </div>
                <div class="modal-body">
                    <label for="log_uname">
                        <span>账号:</span>
                        <input id="log_uname" name="log_uname" type="text" placeholder="input your account">
                    </label>
                    <br>
                    <label for="log_passwd">
                        <span>密码:</span>
                        <input id="log_passwd" name="log_passwd" type="password" placeholder="input your password">
                    </label>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary">登陆</button>
                    <button type="button" class="btn btn-warning" data-dismiss="modal">退出</button>
                </div>
            </div>
        </div>
    </div>

    <!-- LOGIN MODULE -->
    <div id="registerModal" class="modal fade" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span>&times;</span>
                    </button>
                    <h4 class="modal-title">注册会员</h4>
                </div>
                <div class="modal-body">
                    <label for="uname">
                        <span>账号:</span>
                        <input id="reg_uname" name="reg_uname" type="text" placeholder="input your account">
                    </label>
                    <br>
                    <label for="reg_passwd">
                        <span>密码:</span>
                        <input id="reg_passwd" name="reg_passwd" type="password" placeholder="input your password">
                    </label>
                    <label for="reg_confirm_passwd">
                        <span>确认:</span>
                        <input id="reg_confirm_passwd" name="reg_confirm_passwd" type="password" placeholder="confirm your password">
                    </label>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary">注册</button>
                    <button type="button" class="btn btn-warning" data-dismiss="modal">退出</button>
                </div>
            </div>
        </div>
    </div>

    <button class="btn btn-primary" data-toggle="modal" data-target="#loginModal">登录</button>
    <button class="btn btn-warning" data-toggle="modal" data-target="#registerModal">注册</button>
</body>
</html>

对话框其余知识jquery

jQuery方式声明对话框bootstrap

$('#myModal').modal({
    show : true,
    backdrop : false,
    keyboard : false,
    remote : 'index.html',
});

jQuery方式显示对话框ide

$('#myBtn').on('click', function () {
    $('#myModal').modal('show');
});

对话框的事件动画

show.bs.modal  ==> 在show方法调用时当即触发spa

shown.bs.modal  ==> 在模态框彻底显示出来而且CSS动画完成以后触发code

hide.bs.modal ==> 在hide方法调用时 还未关闭隐藏时触发

hidden.bs.modal ==> 在模态框彻底隐藏以后而且CSS动画完成以后触发

$('#myModal').on('show.bs.modal', function () {
    alert('show !');
});

边缘弹出框

<button class="btn btn-lg btn-danger" type="button" data-toggle="popover"
    title="弹出框" data-content="这是一个弹出框">点击弹出/隐藏弹出框</button>
<script>
    $('button').popover();
</script>

其余方法

$('button').popover('show'); //显示
$('button').popover('hide'); //隐藏
$('button').popover('toggle'); //反转显示和隐藏
$('button').popover('destroy'); //隐藏并销毁

事件

show.bs.popover ==> 在调用show方法时触发

shown.bs.popover ==> 在显示整个弹窗时触发

hide.bs.popover ===> 在调用hide方法时触发

hidden.bs.popover ==> 在彻底关闭整个弹出时触发

相关文章
相关标签/搜索