日付ピッカーの最小日付を設定する次のコードがあります。
$( "#sd" ).datepicker({
// before datepicker opens run this function
beforeShow: function(){
// this gets today's date
var theDate = new Date();
// sets "theDate" 2 days ahead of today
theDate.setDate(theDate.getDate() + 2);
// set min date as 2 days from today
$(this).datepicker('option','minDate',theDate);
},
// When datepicker for start date closes run this function
onClose: function(){
// this gets the selected start date
var theDate = new Date($(this).datepicker('getDate'));
// this sets "theDate" 1 day forward of start date
theDate.setDate(theDate.getDate() + 1);
// set min date for the end date as one day after start date
$('#ed').datepicker('option','minDate',theDate);
}
});
今日の日付が 11/14/2012 の場合、datepicker の値は 11/16/2012 です。ただし、日付はサーバーの日時に基づいている必要があるため、サーバーの日付ではなくコンピューターの現在の日付を取得するため、javascript の日付を使用できません。
だから私がしたことは、次のコードに変更することです:
$( "#sd" ).datepicker({
// before datepicker opens run this function
beforeShow: function(){
// this gets today's date
var theDate = new Date();
// sets "theDate" 2 days ahead of today
//theDate.setDate(theDate.getDate() + 2);
theDate.setDate(<?php echo $this->session->userdata('checkin') ?>);
// set min date as 2 days from today
$(this).datepicker('option','minDate',theDate);
},
// When datepicker for start date closes run this function
onClose: function(){
// this gets the selected start date
var theDate = new Date($(this).datepicker('getDate'));
// this sets "theDate" 1 day forward of start date
theDate.setDate(theDate.getDate() + 1);
// set min date for the end date as one day after start date
$('#ed').datepicker('option','minDate',theDate);
}
});
この行を見てください:
theDate.setDate(<?php echo $this->session->userdata('checkin') ?>);
ところで、私は codeigniter セッションを使用しています。
これはうまく機能しますが、datepicker の最小日付が 11/16/2012 に設定されておらず、代わりに 11/2/2012 に設定されていることが問題です。
PHP の値を jQuery に正しく挿入する方法を知っている人はいますか?