Domanda

I am using Jquery's Datepicker and I want to know if it's possible to change the yearRange atribute based on the current month.

In my case, if the month it's different from november or december yearRange its the current year

else it's the current year + 1

Example 1:

current month: april

.datepicker({
        showOn: "button",
        buttonImageOnly: true,
        changeMonth: true,
        changeYear: true,
        yearRange: '-12:+0'

Example 2:

current month: november

.datepicker({
        showOn: "button",
        buttonImage: "../../App_Themes/Samae/images/calendar.png",
        buttonImageOnly: true,
        changeMonth: true,
        changeYear: true,
        yearRange: '-12:+1'

thanks!

È stato utile?

Soluzione

jQuery code

$(function () {
    var d = new Date();
    var month = d.getMonth();
    var range;
    if (month == 10 || month == 11) {
        range = '-12:+1';
    } else {
        range = '-12:+0';
    }
    $('#txtDate').datepicker({
        changeMonth: true,
        changeYear: true,
        yearRange: range
    });
});  

You can check it working out by changing the condition as if (month == 03 || month == 11).

Alternate

$(function () {
    var d = new Date();
    var month = d.getMonth();
    $('#txtDate').datepicker({
        changeMonth: true,
        changeYear: true,
        yearRange: (month == 10 || month == 11) ? '-12:+1' : '-12:+0'
    });
});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top