前端

Bootstrap轻量弹框和模态框

2022-03-30  本文已影响0人  马佳乐

轻量弹框

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <!--移动设备优先-->
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <!--引入Bootstrap CSS-->
        <link rel="stylesheet" href="css/bootstrap.min.css" />
        <title></title>
    </head>

    <body>

        <div class="toast fade" data-autohide="false" style="position: absolute;top: 0;right: 0;">
            <div class="toast-header">
                <h5 class="mr-auto">提示框</h5>
                <button class="close" data-dismiss="toast"><span>&times;</span></button>
            </div>
            <div class="toast-body">
                弹框体:一些提示信息!
            </div>
        </div>
        <button id="btn" class="btn btn-success">弹出弹框</button>

        <!--引入JavaScript和jQuery-->
        <!--jQuery第一个,然后Bootstrap (集成了 Popper.js和Bootstrap.js)-->
        <script src="js/jquery.js"></script>
        <script src="js/bootstrap.bundle.min.js"></script>
    </body>

</html>
<script>
    $(function() {
        $("#btn").click(function() {
            $(".toast").toast("show");
        });
    });
</script>

模态框

        <div class="modal fade" id="mymodal">
            <div class="modal-dialog modal-dialog-centered modal-sm">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5>添加商品</h5>
                        <button class="close" data-dismiss="modal"><span>&times;</span></button>
                    </div>
                    <div class="modal-body">
                        body
                        <p>可添加任意内容</p>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-success">添加商品</button>
                        <button class="btn btn-secondary" data-dismiss="modal">取消添加</button>
                    </div>
                </div>
            </div>
        </div>
        <button class="btn btn-success" data-target="#mymodal" data-toggle="modal">弹出模态框</button>
上一篇下一篇

猜你喜欢

热点阅读