将jQuery fullcalendar集成到PHP网站中

Dyl*_*SUN 11 php jquery calendar fullcalendar

我想将jQuery fullcalendar集成到我的PHP网站中,但我不知道如何处理该事件以及如何使用MySQL的JSON数据.

任何意见,将不胜感激.

Gra*_*ton 15

确保您的PHP可以输出以下HTML代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>

  <script>
  $(document).ready(function(){
    $('#example').calendar();
  });
  </script>

</head>
<body>
  <link rel="stylesheet" href="http://dev.jquery.com/view/trunk/themes/flora/flora.all.css" type="text/css" media="screen" title="Flora (Default)">
<script  src="http://dev.jquery.com/view/trunk/plugins/calendar/jquery-calendar.js"></script>
<input type="text" id="example" value="Click inside me to see a calendar" style="width:300px;"/>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

以下是使用json_encode 的示例:

$(document).ready(function() { 

      $('#calendar').fullCalendar({ 
         draggable: true, 
         events: "json_events.php", 
         eventDrop: function(event, delta) { 
            alert(event.title + ' was moved ' + delta + ' days\n' + 
               '(should probably update your database)'); 
         }, 
         loading: function(bool) { 
            if (bool) $('#loading').show(); 
            else $('#loading').hide(); 
         } 
      }); 

   });
Run Code Online (Sandbox Code Playgroud)

这是PHP代码:

<?php

   $year = date('Y'); 
   $month = date('m');

   echo json_encode(array( 

      array( 
         'id' => 1, 
         'title' => "Event1", 
         'start' => "$year-$month-10", 
         'url' => "http://yahoo.com/" 
      ), 

      array( 
         'id' => 2, 
         'title' => "Event2", 
         'start' => "$year-$month-20", 
         'end' => "$year-$month-22", 
         'url' => "http://yahoo.com/" 
      ) 

   ));

?>
Run Code Online (Sandbox Code Playgroud)


小智 9

"2010-02-11 11:00:00"格式工作正常,为我指定时间(内部没有"T"),解决方案的关键是将事件的"allDay"属性设置为空字符串.