设置cookie和模态不出现的问题

时间:2016-03-04 10:41:48

标签: javascript jquery html css

我试图在延迟2秒后显示模态,并且还希望在显示之前进行cookie验证。

这是我的代码

$(document).ready(function(){
    //$("#myModal").modal('show');
    if ($.cookie('modal_shown') == null) {
        $.cookie('modal_shown', 'yes', { expires: 7, path: '/' });
        setTimeout(function() {
            $('#myModal').modal('show');
        }, 2000);
    }
});
<div class="bs-example">
    <!-- Modal HTML -->
    <div id="myModal" class="modal fade">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">Confirmation</h4>
                </div>
                <div class="modal-body">
                    <p>Do you want to save changes you made to document before closing?</p>
                    <p class="text-warning"><small>If you don't save, your changes will be lost.</small></p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Save changes</button>
                </div>
            </div>
        </div>
    </div>
</div>

我的问题是模态没有出现。如果我没有指定if条件,则会出现模态。请帮忙。

0 个答案:

没有答案