开发者

FullCalendar: Using the script in the construction of <body>

If you make a call script in the construction of <head> - then it works, but if its cause in the construction of <body> - it does not work: (

Work:

<html>
<head>
..
<script type="text/javascript" src="../js/fullcalendar.js"></script>
<script type="text/javascript">
 $(document).ready(function() {
  var date = new Date();
  var d = date.getDate();
  var m = date.getMonth();
  var y = date.getFullYear();
  $('#calendar').fullCalendar({
   editable: true,
   events: [
    {
     title: 'All Day Event',
     start: new Date(y, m, 1)
    }
   ]
  });
 });
</script>
</head>开发者_如何学Go
<body>
<div id='calendar'></div>
</body>
</html>

Not work:

<html>
<head>
..
</head>
<body>
<script type="text/javascript" src="../js/fullcalendar.js"></script>
<script type="text/javascript">
 $(document).ready(function() {
  var date = new Date();
  var d = date.getDate();
  var m = date.getMonth();
  var y = date.getFullYear();
  $('#calendar').fullCalendar({
   editable: true,
   events: [
    {
     title: 'All Day Event',
     start: new Date(y, m, 1)
    }
   ]
  });
 });
</script>
<div id='calendar'></div>
</body>
</html>

Tell me what I am doing wrong? ..


That certainly is surprising! Are you sure you copy-and-pasted correctly? The only explanation that I can see immediately is that it's because the DOM element #calendar isn't loaded yet or something like that but jQuery shouldn't execute $(document).ready until every DOM element is loaded so it's definitely weird.

Your problem is most likely browser non-deterministic meaning it'll most likely work differently in different browsers between refreshes.

Can you try removing all the fullCalendar code from within $(document).ready( and instead just have this:

$(document).ready(function() {
  console.log(document.getElementById('calendar'));
});

Try that INSIDE the head and outside and see what difference it makes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜