>我正在尝试使用bootstrap/jquery在模式对话框中显示完整日历。当模式出现时,除非选择"今天"按钮,否则日历首先不会显示。
我读到我应该使用:
$("#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
在显示模态时调用,因此使用它允许它在打开模态时显示。