使用此代码我只能启用星期日。但是,如果它是一年中的一周,如何禁用星期日。
function settings(date) {
if (date.getDay() == 0) {
return [true, "", "Works"];
} else {
return [false, "", ""];
}
}
$i("#searchsectionbarids").datepicker({
altField: "#alternate",
altFormat: "DD",
dateFormat: 'dd/mm/yy',
beforeShowDay: settings
});
答案 0 :(得分:0)
用它来获取一年中的周数:
Date.prototype.getWeek = function () {
var firstDay = new Date(this.getFullYear(), 0, 1);
var today = new Date(this.getFullYear(), this.getMonth(), this.getDate());
var dayOfYear = ((today - firstDay + 1) / 86400000);
return Math.ceil(dayOfYear / 7)
};
然后
function settings(date) {
if (date.getDay() == 0 && date.getWeek() % 2 == 1) {
return [true, "", "Works"];
} else {
return [false, "", ""];
}
}
答案 1 :(得分:0)
首先,你必须检查一周是否均匀 你可以参考 Get week of year in JavaScript like in PHP
然后您使用逻辑设置日历
祝你好运