这很奇怪,也很复杂,我会尽力解释它。我手工制作日历,计划开源等等。我目前正在寻找谷歌日历的外观和感觉,因为它们似乎是最好的,但我确实计划升级它+开源。一切都在完美运行,除非我单击上个月,以查看上个月,然后运行 ajax 查询,php 返回新日历,但是当它呈现时,它呈现没有任何 <table>
元素,除了没有遇到任何障碍想法?继承人一些代码/图像:
html:
//function to use xml
function xml(){
//need to set up xml to run php for query
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
document.getElementById("calendar").innerHTML= xmlhttp.responseText;
}
};
}
//function to select the previous month
function previousMonth(str){
//since this is the previous month we need to take month -1
var month = str - 1;
//if it is already 1.. then it needs to be 12!
if(str == 1)
{
month = 12;
}
//call xml
xml()
//send dat query
xmlhttp.open("GET","redraw.php?month="+encodeURIComponent(month),true);
xmlhttp.send();
}
重绘.php:
// draws the calendar
function draw_calendar($month,$year){
// table headings
$headings = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
$calendar= '<tr class="calendar-row"><td class="calendar-day-head" id = "cell" style = "min-width:150px;">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>';
// days and weeks vars now
$days_last_month = date('t',mktime(0,0,0,$month-1,1,$year));
$running_day = date('w',mktime(0,0,0,$month,1,$year));
$days_in_month = date('t',mktime(0,0,0,$month,1,$year));
$days_in_this_week = 1;
$day_counter = 0;
$dates_array = array();
$today = date("d");
// row for week one
$calendar.= '<tr class="calendar-row">';
// print "blank" days until the first of the current week
for($x = 0; $x < $running_day; $x++)
{
$calendar.= '<td class = "calendar-day-prev" id = "cell" style = "min-width:150px;"><div class = "day-prev- number" style = "color:#929D9D">'.(($days_last_month -($running_day - 1)) + $x).'</div>';
$calendar.= str_repeat('<p> </p>',2);
$calendar.= '</td>';
$days_in_this_week++;
}
// keep going with days....
for($list_day = 1; $list_day <= $days_in_month; $list_day++)
{
$calendar.= '<td class = "calendar-day" id = "cell" style = " min-width:150px;"';
//if the day is today we obviously need to have a differnet style for it...
if($list_day == $today)
{
$calendar.= ' style = "background-color:#9494B8;font-weight:bol;">';
}
else
{
$calendar.= '>';
}
// add in the day number
$calendar.= '<div class = "day-number">'.$list_day.'</div>';
// THIS IS WHERE I NEED TO QUERY ENTRIES PER DAY
$calendar.= str_repeat('<p> </p>',2);
$calendar.= '</td>';
if($running_day == 6)
{
$calendar.= '</tr>';
if(($day_counter+1) != $days_in_month)
{
$calendar.= '<tr class="calendar-row">';
}
$running_day = -1;
$days_in_this_week = 0;
}
$days_in_this_week++; $running_day++; $day_counter++;
}
// finish the rest of the days in the week
if($days_in_this_week < 8 && $days_in_this_week != 1)
{
for($x = 1; $x <= (8 - $days_in_this_week); $x++)
{
$calendar.= '<td class = "calendar-day-after" id = "cell" style = " min-width:150px;"><div class = "day-post-number" style = "color:#929D9D;">'.$x.'</div>';
$calendar.= str_repeat('<p> </p>',2);
$calendar.= '</td>';
}
};
// final row
$calendar.= '</tr>';
// all done, return result
return $calendar;
}
//draw the calendar
$year = date ('Y');
$month_title = date ('F');
//Sent variables
if(!empty($_REQUEST['month']))
{
$month_display = $_REQUEST['month'];
}
else
{
$month_display = date ('n');
}
echo draw_calendar($month_display,$year);
这是对正在发生的事情的一个很好的描述:
它应该是什么样子:
第一次点击:
js插入了什么<div id = "calendar">
php返回的内容(这部分看似正确):