2010-05-25 78 views
1

不知如何下月设定只显示活跃星期一:显示下个月

我试图做水木清华这样的,但它不会工作

function onlyMondaysNextMonth(date){ 
    var day = date.getDay(); 
    var mDate = date.getMonth() + 1; 

    return { 
     minDate: mDate, 
    }  
    return [(day == 1),''];               
} 

谢谢。

回答

1

使用下面的代码只启用星期一从下月

var minDate = null; 
var now = new Date(); 
if (now.getMonth() == 11) { 
    minDate = new Date(now.getFullYear() + 1, 0, 1); 
} else { 
    minDate = new Date(now.getFullYear(), now.getMonth() + 1, 1); 
} 

/* create datepicker */ 
jQuery(document).ready(function() { 
    jQuery('#datepicker').datepicker({ 
     minDate: minDate,   
     constrainInput: true, 
     beforeShowDay: beforeShowDay 
    }); 
}); 

function beforeShowDay(date) { 
    var day = date.getDay(); 
    if (day == 1) 
     return [true] 
    return [false]; 

} 

工作样品在http://elangovanr.com/samples/jquery/datepickermonday.html托管,供大家参考启动。

+0

试过了你的代码,但似乎没有设置下个月出现。当日历显示时,它仅限制星期几到星期一,但我们仍然在同一个月,而不是下一个。我们只是这样做smth: beforeShowDay:function(date){ $(this).datepicker('option','minDate','+ 1m'); var day = date.getDay(); if(day == 1) return [true] return [false]; \t \t \t \t } 虽然它返回太多递归... – devjs11 2010-05-26 08:50:02

+0

已更新我的代码。而不是使用'getYear'使用'getFullYear' – Elangovan 2010-05-26 10:07:55

+0

'beforeShowDay'可以简化为''function before beforehow(date){ return [date.getDay()== 1]; }' – 2010-05-26 10:10:03