我有这个示例代码,我是从David Walsh实现修改的,我的目标是禁用周末Sat和Sun的按钮。我在实施它时遇到了一些困难。我希望有人可以帮我解决我的问题。
<?php
/*
* Calendar from David Walsh's implementation: http://davidwalsh.name/php-calendar
*/
if(isset($_REQUEST["date"])){
// Get the variable
$chosenDate = explode("/",$_REQUEST["date"]);
$month = $chosenDate[0];
$year = $chosenDate[1];
// Check browser
if(isset($_SERVER['HTTP_USER_AGENT'])){
$agent = $_SERVER['HTTP_USER_AGENT'];
}
/*
* Draws the calendar
*/
// Draw table
$calendar = '<table cellpadding="0" cellspacing="0" class="calendar">';
// Table headings
$headings = array('S','M','T','W','Th','F','S');
$calendar.= '<tr><td class="calendar-day-head">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>';
// Variables to be used
$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;
$current_date = explode("/",date('m/j/Y')); //Gets the current date
$dates_array = array();
// 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-np"> </td>';
$days_in_this_week++;
endfor;
// Keep going with days...
for($list_day = 1; $list_day <= $days_in_month; $list_day++):
// This checks current day so that past days will never be picked
if($list_day < $current_date[1] && $month == $current_date[0] && $year == $current_date[2])
$calendar.= '<td class="calendar-day2">';
else{
if(stristr($agent,"firefox")) $value = 'this.textContent';
else $value = 'innerText';
$calendar.= '<td class="calendar-day" onclick="redirect_to_sample('.$value.')">';
}
// Add in the day number
if($list_day < $current_date[1] && $month == $current_date[0] && $year == $current_date[2])
$calendar.= '<div class="day-number2">'.$list_day.'</div>';
else if($list_day == $current_date[1] && $month == $current_date[0] && $year == $current_date[2])
$calendar.= '<div class="day-number"><u>'.$list_day.'</u></div>';
else
$calendar.= '<div class="day-number">'.$list_day.'</div>';
// For further SQLs put here
$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">';
endif;
$running_day = -1;
$days_in_this_week = 0;
endif;
$days_in_this_week++; $running_day++; $day_counter++;
endfor;
// 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-np"> </td>';
endfor;
endif;
// Final row
$calendar.= '</tr>';
// End the table
$calendar.= '</table>';
// All done, return result
echo $calendar;
}
?>`
将禁用sat和sun的类是&lt; <td class="calendar-day2">
答案 0 :(得分:1)
看起来$running_day
正在跟踪星期几。 0 =星期六&amp; 6 =星期天,所以你可以利用它。
尝试以下方法:
// This checks current day so that past days will never be picked
if($list_day < $current_date[1] && $month == $current_date[0] && $year == $current_date[2])
$calendar.= '<td class="calendar-day2">';}
elseif($running_day == 0 || $running_day == 6) //Check for weekend
{
$calendar.= '<td class="calendar-day weekend">'; }
else{
if(stristr($agent,"firefox")) $value = 'this.textContent';
else $value = 'innerText';
$calendar.= '<td class="calendar-day" onclick="redirect_to_sample('.$value.')">';
}
我已经检查了周末,创建了一个不同的td
标签以及额外的周末css类,因此您可以为周末添加一些额外的样式。
请注意,我还没有对此进行测试,并且正在进行一些猜测。
答案 1 :(得分:-1)
$("#datepicker").datepicker({ beforeShowDay: $.datepicker.noWeekends });