这是我的 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页面代码
<asp:TextBox ID="txt" class="monthPickerStart" Text='<%# Eval(Date", "{0:MMM/dd/yyyy}") %>' runat="server"></asp:TextBox>
问题: 如果他们已经是此文本框中的日期并且当我尝试打开日期选择器时,它会打开当前日期,而不是打开该文本框中存在的日期。例如文本框内的日期 = 5/13/2019,然后当我尝试打开日期选择器时,它会打开当前日期而不是 5/13/2019
最佳答案
根据这个http://api.jqueryui.com/datepicker/#utility-formatDate你必须正确设置日期格式
由于您正在使用 dateFormat: 'MM yy'
来初始化 Datepicker,
输入字段文本值应包含默认值 May 2019
上面的链接中提到了所有支持的日期格式
关于javascript - jQuery 日期选择器不显示绑定(bind)日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54670119/