ThanhLam112358
ThanhLam112358

Reputation: 914

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>.

enter image description here

Here is console error:

enter image description here

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

enter image description here

enter image description here

Upvotes: 0

Views: 990

Answers (2)

huabin gao
huabin gao

Reputation: 1

Take a look at the console is there is an error message, or maybe you forget to import bootstrap.js or modal.js

Upvotes: 0

Muhammad Usman
Muhammad Usman

Reputation: 10148

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

This will trigger your modal to show

Upvotes: 1

Related Questions