Javascript 如何在此日历UI中禁用周末
我从DavidWalsh实现中修改了这个示例代码,我的目标是禁用周末Sat和Sun的按钮。我在实施它时遇到了一些困难。我希望有人能帮我解决我的问题`Javascript 如何在此日历UI中禁用周末,javascript,php,css,ajax,Javascript,Php,Css,Ajax,我从DavidWalsh实现中修改了这个示例代码,我的目标是禁用周末Sat和Sun的按钮。我在实施它时遇到了一些困难。我希望有人能帮我解决我的问题` <?php /* * Calendar from David Walsh's implementation: http://davidwalsh.name/php-calendar */ if(isset($_REQUEST["date"])){ // Get the variable $chosenDate = expl
<?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;
}
?>`
看起来$running\u day
正在跟踪一周中的哪一天。0=周六&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.')">';
}
//这将检查当前日期,以便永远不会拾取过去的日期
如果($list_day<$current_date[1]&&$month==$current_date[0]&&$year==$current_date[2])
$calendar.='';}
elseif($running_day==0 | |$running_day==6)//检查周末
{
$calendar.='';}
否则{
if(stristr($agent,“firefox”)$value='this.textContent';
else$value='innerText';
$calendar.='';
}
我已经检查了weekend,创建了一个不同的td
标记,其中包含weekend的附加css类,这样您就可以为weekend添加一些附加样式
请注意,我还没有测试过这一点,只是做了一点猜测。如何实现它?所有禁用的日期都在这个类中。问题不涉及datepicker
jquery插件。这是一个php实现。在回答之前,你应该更仔细地阅读这个问题。我已经弄明白了:只需将($running|u day==0 |$$running|u day==6)添加到if($list|u day<$current_date[1]&&&$month=$current_date[0]&$year==current| date[2])我已经弄明白了:只需将($running|($running| day==0 | running| day==0&$running| day==6))添加到if中即可(($list_day<$current_date[1]&&&$month==$current_date[0]&&$year=$current_date[2])这是一个可能的解决方案,但为了使事情更简单,只需将($running_day==0 | running_day==6))添加到if($list_day<$current_date[1]&$month=$current_date[0]&$year=$current_date[2])@tomjerry,这是我最初的想法,但你可能希望与过去的日期不同地处理周末。例如,除了样式设置之外,你还可以添加标题属性以提供一些反馈title='请选择一个工作日'
// 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.')">';
}