如何在编辑案例中将日期设置为Datepicker文本框

时间:2017-01-05 06:12:12

标签: jquery

如何在编辑案例中将日期设置为Datepicker文本框。

我在下面写了创建日期的代码

<footer id="site_footer">
    <span>Site Name &copy; 2017 | Powered by <a href="https://wordpress.org/">WordPress</a> |<div id="phpelem"> <?php wp_nav_menu(array('theme_location' => 'footer_nav')); ?> </div> |</span>
</footer>

<script>
    document.getElementById("phpelem").style.display = "inline-block";
    var searchEles = document.getElementById("phpelem").children;
    for(var i = 0; i < searchEles.length; i++) {
        searchEles[i].style.display = "inline-block";
    }
</script>

现在, 如何在datepicker中设置先前设置的日期?

我尝试过如下, $(“#txtDate”)。datepicker()。datepicker('setDate',Date); 和 $( “#txtDate”)VAL(日期);

2 个答案:

答案 0 :(得分:0)

   $(function() {
   $( "#Start_Date" ).datepicker({ dateFormat: 'dd-m-yy',
  showOn: "button",
  buttonImage: "../I/cal.gif",// you add your own image in your folder for date
  minDate:'<?php echo $minDate; ?>',
  maxDate:'<?php echo $maxDate; ?>',
  buttonImageOnly: true,
  firstDay:1,
  minDate: -0,
  beforeShowDay: checkDisabled,
  changeMonth: true,
  changeYear: true,
  beforeShow: function(input, inst)
  {         inst.dpDiv.css({marginTop: -input.offsetHeight + 'px', marginLeft: input.offsetWidth-210 + 'px'});        }});

  });

在JS中尝试上述脚本,#Start_Date将是您输入标记的id

答案 1 :(得分:0)

尝试一下。这可能会解决您的问题。

$(document).ready(function () {
 $("#txtDate").datepicker().datepicker("setDate", new Date());
});