문제

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!

도움이 되었습니까?

해결책

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'
    });
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top