简体   繁体   English

jQuery datepicker 不显示绑定日期

[英]jQuery datepicker not showing binded date

This is my jquery datepicker这是我的 jquery 日期选择器

$(".monthPickerStart").datepicker({
      dateFormat: 'MM yy',
      changeMonth: true,
      changeYear: true,
      showButtonPanel: true,
      onClose: function (dateText, inst) {
                var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
                var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
                $(this).val($.datepicker.formatDate('d M,yy', new Date(year, month, 1)));
      }
});

$(".monthPickerStart").focus(function () 
      $(".ui-datepicker-calendar").hide();
      $("#ui-datepicker-div").position({
            my: "center top",
            at: "center bottom",
            of: $(this)
      });
});

aspx page code aspx页面代码

<asp:TextBox ID="txt" class="monthPickerStart" Text='<%# Eval(Date", "{0:MMM/dd/yyyy}") %>' runat="server"></asp:TextBox>

Problem: If their is already a date in this text box and when I try to open datepicker, then it opens the current date, rather than opening the date which is present inside that textbox.问题:如果它们已经是此文本框中的日期,并且当我尝试打开日期选择器时,它会打开当前日期,而不是打开该文本框中存在的日期。 for example date inside textbox = 5/13/2019, then when i try to open datepicker then it opens current date instead of 5/13/2019例如文本框内的日期 = 5/13/2019,然后当我尝试打开日期选择器时,它会打开当前日期而不是 5/13/2019

根据这个http://api.jqueryui.com/datepicker/#utility-formatDate你必须正确设置日期格式因为你使用dateFormat: 'MM yy'来初始化 Datepicker,输入字段文本值应该包含默认值为May 2019上面链接中提到了所有支持的日期格式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM