我在我的项目中使用Caleran
作为日期选择器。在这种情况下,当用户单击任意日期时,我将选择一个特定的星期,如下图所示。
我有相应的代码
$("#caleran-ex-1").caleran({
startOnMonday: true,
calendarCount: 1,
//select a whole week in a row...
onfirstselect: function(elem, start) {
console.log(elem.config.startDate.format('dddd'));
if (elem.config.startDate.format('dddd') == "Sunday") {
elem.config.startDate = moment(start).startOf("week").subtract(6, "days");
elem.config.endDate = moment(start);
} else {
elem.config.startDate = moment(start).startOf("week").add(1, "days");
elem.config.endDate = moment(start).endOf("week").add(1, "days");
}
elem.globals.endSelected = true;
elem.globals.startSelected = false;
elem.globals.hoverDate = null;
elem.$elem.find(".caleran-apply").removeAttr("disabled");
elem.updateInput();
console.log(elem.config.startDate.format("DD/MM/YYYY") + " - " + elem.config.endDate.format("DD/MM/YYYY"));
},
});