jQuery UI Datepicker - setDate 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11962747/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 11:09:01  来源:igfitidea点击:

jQuery UI Datepicker - setDate not working

jqueryjquery-uijquery-ui-datepicker

提问by Ryan Grush

I know this question has been asked on SO before, but I can't figure out what I'm missing. Here is a simple Fiddle.

我知道之前已经在 SO 上问过这个问题,但我不知道我错过了什么。这是一个简单的Fiddle

The jquery:

jQuery:

var myDate = new Date(1978,2,11) 
$('#datepicker').datepicker('setDate', myDate);

回答by John Koerner

You have to initialize the datepicker first:

您必须先初始化日期选择器:

    $('#datepicker').datepicker();

When you pass setDate, you are calling a method which assumes the datepicker has already been initialized on that object.

当您传递 setDate 时,您正在调用一个方法,该方法假定日期选择器已在该对象上初始化。

http://jsfiddle.net/tbYPf/4/

http://jsfiddle.net/tbYPf/4/