我需要jQuery datepicker的帮助。我有一系列日期。我需要禁用所有日期,除了此数组中的日期。我有代码工作,它完全相反。我用PHP创建日期数组(我知道他们的日期功能更好),然后将它们带入javascript。我正在使用带有刀片模板的laravel框架。如果有人可以修改我必须工作的东西或者有更好的解决方案,那就太棒了!
启用日期: - 除非是星期三,否则每周三都可以使用以下星期三 - 每个其他星期六从2015年7月3日开始提供
这是我的代码:
HTML
<div class="form-group">
<div class="col-md-6">
{{ Form::text('orientation', '', array('class' => 'form-control', 'id' => 'orientation',
'placeholder' => 'Orientation Date', 'required' => 'required')) }}
</div>
</div>
的Javascript
$(function() {
var array = {{$data['availableSat']}}
$('#orientation').datepicker({
beforeShowDay: function(date){
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
alert(array.indexOf(string));
return [ array.indexOf(string) == -1 ]
}
});
});
PHP
public function getMoreInfo()
{
//Gather Orientation Dates
$time = time();
$dayName = date("D", strtotime("now"));
//First get the available Wednesdays
if ($dayName === "Wed")
{
$wed1 = date('m/d/Y', strtotime('+1 week Wednesday'));
$wed2 = date('m/d/Y', strtotime('+2 week Wednesday'));
$wed3 = date('m/d/Y', strtotime('+3 week Wednesday'));
$sqlWed1 = date('Y-m-d', strtotime('+1 week Wednesday'));
$sqlWed2 = date('Y-m-d', strtotime('+2 week Wednesday'));
$sqlWed3 = date('Y-m-d', strtotime('+3 week Wednesday'));
}
else
{
$wed1 = date('m/d/Y', strtotime('next Wednesday'));
$wed2 = date('m/d/Y', strtotime('+1 week Wednesday'));
$wed3 = date('m/d/Y', strtotime('+2 week Wednesday'));
$sqlWed1 = date('Y-m-d', strtotime('next Wednesday'));
$sqlWed2 = date('Y-m-d', strtotime('+1 week Wednesday'));
$sqlWed3 = date('Y-m-d', strtotime('+2 week Wednesday'));
}
$data['availableWed'][] = $sqlWed1;
$data['availableWed'][] = $sqlWed2;
$data['availableWed'][] = $sqlWed3;
//Get the available Saturdays -> Every other sat can be derived by using week numbers and checking for odd or even
$week = date("W"); //php function for current week number
//Evaluate the sat for a few weeks out
for ($i=0; $i<4; $i++)
{
$lastDigitWeek = substr($week,-1);
//If the week is odd then there is orientation
if ($lastDigitWeek == '1' || $lastDigitWeek == '3' || $lastDigitWeek == '5' || $lastDigitWeek == '7' || $lastDigitWeek == '9')
{
$time2 = strtotime('Saturday', $time);
$time3 = gmdate("Y-m-d", $time2);
$Saturdays[$i] = "N/A";
//Disabled Saturdays
$disableDates[] = $time3;
}
else
{
if ($dayName === "Sun")
{
$time2 = strtotime('+1 week Saturday', $time);
$time3 = gmdate("m/d/Y", $time2);
$time4 = gmdate("Y-m-d", $time2);
}
else
{
$time2 = strtotime('Saturday', $time);
$time3 = gmdate("m/d/Y", $time2);
$time4 = gmdate("Y-m-d", $time2);
}
//Available Saturdays
$Saturdays[$i] = $time3;
$saturdaysSQL[] = $time4;
}
$week = $week + 1;
$time = $time + 604800;
}
$data['availableSat'] = json_encode($saturdaysSQL);
$data['availableWed'] = json_encode($data['availableWed']);
return View::Make('apps.newHire.menuMoreInfo')->with('data', $data);
}
产地:
谢谢大家,
安东尼
答案 0 :(得分:0)
如bobdye所述
return [array.indexOf(string)!== -1]