douyou7072
2014-10-09 18:54
浏览 317

如何在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"/> 

图片转代码服务由CSDN问答提供 功能建议

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

   &lt;?php print“$ test_date”?&gt;  - &GT; 返回2014,10,25 
&lt; script&gt; 
 
 $(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()); 
 
 / n  /.datepicker("setDate","<?php echo $ test_date;?&gt;“;  - &gt;这不起作用
 //返回空白日期
}); 
&lt; / script&gt; \  n   
 
 

默认日期设置为当前日期。有没有办法用从php传递到我的表单的变量动态设置默认日期?即我渲染时 我传递给它的表格$ test_date =“2014,12,25”

这里是表格的顶部:

   &lt; form name =“myForm”action =“createevent.php”onsubmit =“return validateForm()”method =“get”&gt; 
&lt; h1 style =“color:blue;”&gt; Skipper输入页面&lt; / h1&gt  ; 
&lt; div class =“skipperinput”“&gt; 
 
&lt;输入典型值 e =“text”id =“mydate”name =“mydate”value =“”/&gt;&lt; br&gt; 
&lt; label&gt;日期&lt; / label&gt; 
&lt; input type =“hidden”id =“mydatex”  NAME = “mydatex”/&GT;  
   
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dskpywvki951583595 2014-10-09 19:02
    已采纳
     .datepicker("setDate", new Date("<?php echo $new_default_date; ?>"));
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题