获取当前点击日期:
点击其他月份时,选择的天会增加一个样式:sc-othermenth,根据这个样式加上已点击样式,判断天数大小,由此计算月份,特殊时计算年份即可。
if ($(".sc-selected").hasClass("sc-othermenth")) { //判断是否是其他月
if (day <= 14) { //下个月
if (month == 12) {
month = 1;
year = year + 1;
} else {
month = month + 1;
}
}
if (day >= 15) { //上个月
if (month == 1) {
month = 12;
year = year - 1;
} else {
month = month - 1;
}
}
}我是这么做的,大家试试
{
key: 'getSelectedDay',
value: function getSelectedDay() {
var selectYear = this.container.querySelector('.sc-select-year').value;
var selectMonth = this.container.querySelector('.sc-select-month').value;
var selectDay = this.selectDay.querySelector('.day').innerHTML;
var cq = this.container.querySelector(".sc-selected.sc-othermenth");
if (cq) {
//点击的日期是其他月份的
if (selectDay > 15) {
//上个月
return new Date(selectYear, selectMonth - 2, selectDay);
} else {
//下个月
return new Date(selectYear, selectMonth, selectDay);
}
}
return new Date(selectYear, selectMonth - 1, selectDay);
}