Basically what I'm wanting is my datepicker to echo out the month that it just changed to after selecting a new month. My code is currently:
$(function() {
$('#datepicker').datepicker({
onChangeMonthYear: function () {
$('#date').text("Changed Month to: " + *what to put here*);
}
});
});
I've tried everything I can think of, but the only thing I can even get me to return a month is if I get it from the date via $(this).val(), but that only returns me the month of the sel开发者_StackOverflow社区ected date, whereas I just want to know when the month is changed, and what it was changed to. Any help steering me in the right direction is greatly appreciated.
From jQuery UI Documentation
Allows you to define your own event when the datepicker moves to a new month and/or year. The function receives the selected year, month (1-12), and the datepicker instance as parameters. this refers to the associated input field.
Code examples
Supply a callback function to handle the onChangeMonthYear event as an init option.
$('.selector').datepicker({
onChangeMonthYear: function(year, month, inst) { ... }
});
As you can see from above, there are 3 input params that you're omitting in your code.
onChangeMonthYear: function (year, month, inst) { var date = new Date(year, month - 1); alert(date)}
Use this code this will solve your problem.
精彩评论