douyou7072 2014-10-09 18:54
浏览 652
已采纳

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

I'm using datepicker with the following script:

<?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>

the default date is set to the current date. Is there a way to dynamically set the default date with a variable passed into my form from php? i.e When I render the form I pass into it $test_date which = "2014,12,25"

and here's the top of the form:

<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条回答 默认 最新

  • dskpywvki951583595 2014-10-09 19:02
    关注
     .datepicker("setDate", new Date("<?php echo $new_default_date; ?>"));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?