在jqueryui DatePicker上设置“选项"会清除文本框的值吗? [英] Setting 'option' on jqueryui DatePicker clears the textbox's value?
问题描述
我在这里突出了示例:
基本上,需要在datepicker控件上设置一个单独的事件(在构造上未知).这清除"了真正令人讨厌的文本框值,因为初始构造并没有.
Basically, a separate event (not known at construction) needs to set "option","maxDate"
on the datepicker control. This 'clears' the textbox value which is really annoying, as the initial construction does not.
任何人都可以提供解决方案吗?
Can anyone offer a solution?
将第5行更改为:
$("#myinput").datepicker("destroy");
$("#myinput").datepicker({minDate:new Date(), maxDate: new Date()});
使它按预期方式工作,但这是一种非常凌乱的方法.
makes it work as expected, but is a seriously messy approach.
推荐答案
格式存在问题.您的初始值dd-mm-yyyy
与日期选择器的默认格式不匹配.要解决此问题,请在创建日期选择器时将初始值设置为正确的格式,并将格式指定为dateFormat
.
It's an issue with the format. Your initial value dd-mm-yyyy
doesn't match the datepickers default format. To resolve, set the initial value to the correct format and specify the format as dateFormat
when creating the datepicker.
更改为:
<input id="myinput" type="text" value="01-01-1970" />
并且:
//construct datepicker
$("#myinput").datepicker({minDate:new Date(), dateFormat : "dd-mm-yy"});
//later on, a seperate event changes the maxDate property
//but this 'clears' the existing value in the textbox!
$("#myinput").datepicker("option","maxDate", new Date());
这篇关于在jqueryui DatePicker上设置“选项"会清除文本框的值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!