在我的 php 文件中,我有:
$startDate = new DateTime('2013-08-15');
$endDate = new DateTime('2013-10-15');
echo '<div id="filterStartDate">Start Date:</div>';
echo '<div id="filterEndDate">End Date:</div>';
然后在javascript中我有:
$('#filterStartDate').datepicker({
changeMonth:true,
changeYear:true,
dateFormat:'yy-mm-dd',
onSelect: function( selectedDate ) {
$( "#filterEndDate" ).datepicker( "option", "minDate", selectedDate );
}
});
$('#filterEndDate').datepicker({
changeMonth: true,
changeYear: true,
dateFormat:'yy-mm-dd',
onSelect: function( selectedDate ) {
$( "#filterStartDate" ).datepicker( "option", "maxDate", selectedDate );
alert($("#filterEndDate").val());
}
});
我想知道是否有办法在 PHP 的 datePicker 上设置初始日期。我知道我可以从 php 中生成 javascript,但我认为这很混乱,并希望保持分离。如果有类似的东西会很棒:
echo '<div id="filterStartDate" value="'.$startDate->format('Y-m-d').'">Start Date:</div>';