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

如何在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; ?>"));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题