Fullcalendar 不在 bootstrap 模态中呈现

Fullcalendar doesn't render in bootstrap modal

我正在尝试使用 bootstrap/jquery 在模态对话框中显示完整日历。 当模式出现时,日历最初不会显示,除非选择 'Today' 按钮。

我读到我应该使用:

$("#calendar").fullCalendar('render');

这似乎不起作用。

我在这里重现了整个问题。我使用了链接作为我的参考,所以如果你 运行 这个脚本在 Chrome.

中,你可以看到问题

<!DOCTYPE html>
<html>
<head>
    
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link href="http://cdnjs.cloudflare.com/ajax/libs/fullcalendar/1.6.4/fullcalendar.css" rel="stylesheet"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js" type="text/javascript"></script>        
<!-- IMPORTANT! fullcalendar depends on jquery-ui.min.js for drag & drop support -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/fullcalendar/1.6.4/fullcalendar.min.js"></script>

</head>
<body>
<a data-toggle="modal" id="add_appointment" href="#modal_form_addappt" class="btn btn-default btn-sm">Add... </a>
    
<!-- /.modal -->
<div class="modal fade" id="modal_form_addappt" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Add New Appointment...</h4>
            </div>
            <div class="modal-body">

                <div id="calendar"></div>
                
            </div>
            <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
        <button class="btn btn-primary">Save changes</button>
        </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

<script>
           
$("#calendar").fullCalendar({
});
    
$('#modal_form_addappt').on('show.bs.modal', function () {
       $("#calendar").fullCalendar('render');
});
    
</script>
    
</body>
       
</html>

你用错了方法。将 show.bs.modal 更改为 shown.bs.modal:

<!DOCTYPE html>
<html>
<head>
    
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link href="http://cdnjs.cloudflare.com/ajax/libs/fullcalendar/1.6.4/fullcalendar.css" rel="stylesheet"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js" type="text/javascript"></script>        
<!-- IMPORTANT! fullcalendar depends on jquery-ui.min.js for drag & drop support -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/fullcalendar/1.6.4/fullcalendar.min.js"></script>

</head>
<body>
<a data-toggle="modal" id="add_appointment" href="#modal_form_addappt" class="btn btn-default btn-sm">Add... </a>
    
<!-- /.modal -->
<div class="modal fade" id="modal_form_addappt" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Add New Appointment...</h4>
            </div>
            <div class="modal-body">

                <div id="calendar"></div>
                
            </div>
            <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
        <button class="btn btn-primary">Save changes</button>
        </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

<script>
           
$("#calendar").fullCalendar({
});
    
$('#modal_form_addappt').on('shown.bs.modal', function () {
       $("#calendar").fullCalendar('render');
});
    
</script>
    
</body>
       
</html>

show 被调用来显示模态,shown 在显示模态时被调用,因此使用它可以在打开模态时显示它。