我正在尝试在我的 jquery ui datepicker 中设置一个初始值。我尝试了几种不同的方法,但似乎没有显示日期,它是空的。
var idag = new Date();
$("#txtFrom").datepicker("setDate", idag - 2);
$("#txtTom").datepicker("setDate", idag);
$("#txtFrom").datepicker("refresh");
$("#txtTom").datepicker("refresh");
最佳答案
这个简单的example对我有用...
HTML
<input type="text" id="datepicker">
JavaScript
var $datepicker = $('#datepicker');
$datepicker.datepicker();
$datepicker.datepicker('setDate', new Date());
我可以通过简单地查看 @ the manual 来创建它并阅读 setDate
的解释:
.datepicker( "setDate" , date )
Sets the current date for the datepicker. The new date may be a Date object or a string in the current date format (e.g. '01/26/2009'), a number of days from today (e.g. +7) or a string of values and periods ('y' for years, 'm' for months, 'w' for weeks, 'd' for days, e.g. '+1m +7d'), or null to clear the selected date.
关于javascript - 使用 jquery 在 datepicker 中设置初始值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9921944/