如何在datepicker中动态设置默认日期

时间:2014-10-09 18:54:44

标签: php jquery html datepicker

我使用带有以下脚本的datepicker:

<?php print "$test_date" ?> --> returns 2014,10,25
<script>

$(function() {

$("#mydate").datepicker({
    onSelect: function(dateText, inst) {
    var dateAsString = dateText;  

    var date = $('#mydate').val();
    var datex = date.replace(/[/]/g,"-"); // 01-01-2013 01:21
    $('#mydatex').val(datex);


  }
})
     .datepicker("setDate",new Date());

     //.datepicker("setDate","<?php echo $test_date; ?>";  --> this doen't work 
     // returns blank date
});
</script>

默认日期设置为当前日期。有没有办法动态设置默认日期与从PHP传递到我的表单的变量?即当我渲染表格时,我将其传递给它$ test_date =&#34; 2014,12,25&#34;

并且这里是表格的顶部:

<form name="myForm" action="createevent.php" onsubmit="return validateForm()" method="get"> 
<h1 style="color:blue;">Skipper Input Page</h1>
<div class="skipperinput"">

<input type="text" id="mydate" name="mydate" value= ""/><br>
<label>Date</label>
<input type="hidden" id="mydatex" name="mydatex"/> 

1 个答案:

答案 0 :(得分:1)

 .datepicker("setDate", new Date("<?php echo $new_default_date; ?>"));