简体   繁体   中英

Bootstrap modal not auto show

I have a problem with Bootstrap modal.

I want to show my modal with correct if condition. But it not show.

Here is my code:

<?php if (isset($_['messages']) && $_['messages'] == 'ok'): ?>
    <div class="alert alert-success">
        Chúc mừng quý khách đã đăng kí thành công VNPT Drive - Dịch vụ Lưu trữ và chia sẻ trực tuyến hàng đầu Việt Nam. Quý khách vui lòng đăng nhập để sử dụng dịch vụ.<br>
    </div>
    <!--LAM test -->

    <div class="container">
        <div class="modal fade" id="myModal2" role="dialog">
                <div class="modal-dialog">
                    <!-- Modal content-->
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                            <h4 class="modal-title"><?php echo "Title"; ?></h4>
                        </div>
                        <div class="modal-body">
                            <p><?php echo "LAMMMMMM"; ?></p>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Đóng</button>
                        </div>
                    </div>
                </div>
        </div>  
    </div>
    <script>
        $(function() {
        $("#myModal2").modal();
        });
    </script>

This is a result.

It only show <div>Chúc mừng...bla bla...</div> .

在此处输入图片说明

Here is console error:

在此处输入图片说明

PS: I try to add button and open my modal by click button, It's work. It only not auto show modal.

在此处输入图片说明

在此处输入图片说明

Change $("#myModal2").modal(); to $("#myModal2").modal('show'); to open modal with jquery.

This will trigger your modal to show

看一下控制台是否有错误消息,或者也许您忘记导入bootstrap.js或modal.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM