开发者

currentMonth problem in jQuery

$(function() {
    $('#datepicker').datepicker({
     开发者_JAVA技巧   beforeShowDay: daysToMark,
        onSelect: function(date,evt){
            if (evt.currentMonth < 10){
                evt.currentMonth = "0"+evt.currentMonth;
                }
            if (evt.currentDay < 10){
                evt.currentDay = "0"+evt.currentDay;
                }
                //var Month = evt.currentMonth;
                //console.log(nMonth);
                return [true, "fancy-hover", ""];
                daysToMark(evt.currentYear+"-"+evt.currentMonth+"-"+evt.currentDay);
            }
    });
});

but when i'm checking in console year is 2011, day is 7 and month has a problem, it show 06 not 07. i guess it is an array problem counting from 0 but how can i fix it?

I tried this ->

evt.currentMonth = evt.currentMonth + 1

but with no result.

thanks in advance


Months in JavaScript are zero indexed. Hence January = 0 December = 11

I presume you'd be best to add your +1 to this line:

daysToMark(evt.currentYear+"-"+evt.currentMonth+"-"+evt.currentDay);

like this somehow:

var template = '{{YEAR}}-{{MONTH}}-{{DAY}}';
daysToMark( template.replace(/{{YEAR}}/, evt.currentYear).replace(/{{MONTH}}/, Number(evt.currentMonth) + 1).replace(/{{DAY}}/, evt.currentDay));


You cant change the date value of date picker by changing it on passed parameter. If you want to reset date pickers time you have to use. And like Mark said all enumerations in JavaScript are zero indexed.

$('#datepicker').datepicker("setDate", new Date());

Here you can read more about Date object

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜