Ale*_*sio 51 jquery jquery-ui-datepicker
我有一个jQuery-UI datepicker的问题,我搜索和搜索但我没有找到答案.我有以下代码:
<script type="text/javascript">
$(function() {
$("#birthdate" ).datepicker({
changeMonth: true,
changeYear: true,
yearRange: '1920:2010',
dateFormat : 'dd-mm-yy',
defaultDate: '01-01-1985'
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
我希望当用户在#birthdate输入中单击当前选择的日期时01-01-1985,现在它正在设置当前日期.
Cod*_*uth 49
尝试传入一个Date对象.我不明白为什么它不能以你输入的格式工作:
<script type="text/javascript">
$(function() {
$("#birthdate" ).datepicker({
changeMonth: true,
changeYear: true,
yearRange: '1920:2010',
dateFormat : 'dd-mm-yy',
defaultDate: new Date(1985, 00, 01)
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
http://api.jqueryui.com/datepicker/#option-defaultDate
通过Date对象指定实际日期,或者指定当前dateFormat中的字符串,或者从今天开始的天数(例如+7)或一串值和句点('y'表示年份,'m'表示月份, 'w'持续数周,'d'持续数天,例如'+ 1m + 7d'),或今天为null.
Uma*_*ain 15
您可以尝试使用下面的代码.
它将使默认日期成为您要查找的日期.
$('#birthdate').datepicker("setDate", new Date(1985,01,01) );
Run Code Online (Sandbox Code Playgroud)
Shi*_*ryu 11
看见那个:
如果该字段为空,请在第一次打开时设置要突出显示的日期.通过Date对象指定实际日期,或者指定当前dateFormat中的字符串,或者从今天开始的天数(例如+7)或一串值和句点('y'表示年份,'m'表示月份, 'w'持续数周,'d'持续数天,例如'+ 1m + 7d'),或今天为null.
如果无法识别当前的dateFormat,您仍然可以使用Date对象 new Date(year, month, day)
在你的例子中,这应该工作(我没有测试它):
<script type="text/javascript">
$(function() {
$("#birthdate" ).datepicker({
changeMonth: true,
changeYear: true,
yearRange: '1920:2010',
dateFormat : 'dd-mm-yy',
defaultDate: new Date(1985,01,01)
});
});
</script>
Run Code Online (Sandbox Code Playgroud)