I'm trying to use jQuery UI datepicker in my project and it seems that I can't set date at render time in format as "MM yy"
. But I still can change it in onClose
method after page is loaded. If I change initial date format to "yy-mm-dd"
initial date is set correctly.
Example is here:
/
In this example if you change dateFormat
to "yy-mm-dd"
then the date is set correctly to a value of realDate
variable. If dateFormat
is set to "MM yy"
, the date is set to current date.
I appreciate any help.
I'm trying to use jQuery UI datepicker in my project and it seems that I can't set date at render time in format as "MM yy"
. But I still can change it in onClose
method after page is loaded. If I change initial date format to "yy-mm-dd"
initial date is set correctly.
Example is here:
http://jsfiddle/DBpJe/1446/
In this example if you change dateFormat
to "yy-mm-dd"
then the date is set correctly to a value of realDate
variable. If dateFormat
is set to "MM yy"
, the date is set to current date.
I appreciate any help.
Share Improve this question asked Nov 7, 2013 at 5:37 Andy J.Andy J. 3542 gold badges4 silver badges14 bronze badges 4- so what is your problem, you don't to set current date? – Praveen Commented Nov 7, 2013 at 5:39
- here is a jquery asset might help u..jqueryui./resources/demos/datepicker/date-formats.html – codebreaker Commented Nov 7, 2013 at 5:47
-
I suppose that if
.datepicker('setDate', realDate)
fails, then date is set to current date by default. – Andy J. Commented Nov 7, 2013 at 5:50 - This demo is very good, but it can't help, because I need dateFormat to contain only month and year – Andy J. Commented Nov 7, 2013 at 5:53
1 Answer
Reset to default 4try setting date at the end instead of in beginning,here is working demo http://jsfiddle/DBpJe/1446/
$(function() {
var queryDate = '2009-11-01',
dateParts = queryDate.match(/(\d+)/g)
realDate = new Date(dateParts[0], dateParts[1] - 1, dateParts[2]);
// months are 0-based!
$('#startDate').datepicker({
dateFormat: "MM yy"
}) // format to show
.datepicker("option", "changeMonth", true)
.datepicker("option", "changeYear", true)
.datepicker("option", "showButtonPanel", true)
.datepicker("option", "onClose", function(e){
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker("setDate",new Date(year,month,1));
}).datepicker('setDate',realDate);
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744387977a4571762.html
评论列表(0条)